HDU 4348 I - To the moon 可持续化
队友套的可持续化线段树,徘徊在RE和MLE之间多发过的。。。
复用结点新的线段树平均要log2N个结点。
其实离线就好,按照时间顺序组织操作然后dfs。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> using namespace std; const int maxn = ;
int n, m;
struct Node {
long long d, td;
int timelabel;
Node() {};
Node(long long _d, long long _td, int t) {
d = _d; td = _td; timelabel = t;
}
};
vector<Node> bit[maxn];
long long a[maxn], sum[maxn] = {}; inline int lowbit(int x)
{
return x & (-x);
} inline void update(int x, long long w, int timelabel)
{
int size;
long long tw = w * x;
while (x <= n) {
size = bit[x].size();
bit[x].push_back(bit[x][size-]);
size++;
bit[x][size-].d += w;
bit[x][size-].td += tw;
bit[x][size-].timelabel = timelabel;
x += lowbit(x);
}
} inline long long getsum(int x, int timelabel)
{
long long sd = , std = ;
int size, ox = x;
while (x > ) {
size = bit[x].size();
while (bit[x][size-].timelabel > timelabel) {
size--;
}
sd += bit[x][size-].d;
std += bit[x][size-].td;
x -= lowbit(x);
}
return (ox + ) * sd - std;
} inline long long getans(int x, int y, int timelabel)
{
return sum[y] - sum[x-] + getsum(y, timelabel) - getsum(x - , timelabel);
} inline void back(int timelabel)
{
int size;
for (int i = ; i <= n; ++i) {
size = bit[i].size();
while (bit[i][size-].timelabel > timelabel) {
bit[i].pop_back();
size--;
}
}
} void build()
{
for (int i = ; i <= n; ++i) {
bit[i].clear();
bit[i].push_back(Node(0LL, 0LL, ));
}
} int main()
{
//freopen("in.txt","r",stdin);
int cas = ;
while (scanf("%d%d", &n, &m) != EOF) {
if (cas++) printf("\n");
for (int i = ; i <= n; ++i) {
scanf("%lld\n", &a[i]);
sum[i] = sum[i-] + a[i];
}
char op[];
int x, y, z;
int timelabel = ;
build();
while (m--) {
scanf("%s", op);
if (op[] == 'Q') {
scanf("%d%d", &x, &y);
printf("%lld\n", getans(x, y, timelabel));
} else if (op[] == 'C') {
scanf("%d%d%d", &x, &y, &z);
timelabel++;
update(x, z, timelabel);
update(y + , -z, timelabel);
} else if (op[] == 'H') {
scanf("%d%d%d", &x, &y, &z);
printf("%lld\n", getans(x, y, z));
} else {
scanf("%d", &x);
timelabel = x;
back(x);
}
}
}
return ;
}
HDU 4348 I - To the moon 可持续化的更多相关文章
- 【HDU - 4348】To the moon(主席树在线区间更新)
BUPT2017 wintertraining(15) #8G 题意 给一个数组a,有n个数,m次操作.\(N, M ≤ 10^5, |A i| ≤ 10^9, 1 ≤ l ≤ r ≤ N, |d| ...
- hdu 4348 To the moon (主席树)
版权声明:本文为博主原创文章,未经博主允许不得转载. hdu 4348 题意: 一个长度为n的数组,4种操作 : (1)C l r d:区间[l,r]中的数都加1,同时当前的时间戳加1 . (2)Q ...
- HDU 4348.To the moon SPOJ - TTM To the moon -可持久化线段树(带修改在线区间更新(增减)、区间求和、查询历史版本、回退到历史版本、延时标记不下放(空间优化))
To the moon Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- hdu 4348 To the moon (主席树 区间更新)
链接: http://acm.hdu.edu.cn/showproblem.php?pid=4348 题意: 4种操作: C l r c 区间[l,r]加c,时间+1 Q l r 询问当前时 ...
- HDU 4348 To the moon 主席树 在线更新
http://acm.hdu.edu.cn/showproblem.php?pid=4348 以前做的主席树没有做过在线修改的题做一下(主席树这种东西正经用法难道不是在线修改吗),标记永久化比较方便. ...
- HDU 4348 SPOJ 11470 To the moon
Vjudge题面 Time limit 2000 ms Memory limit 65536 kB OS Windows Source 2012 Multi-University Training C ...
- HDU 4348 To the moon 可持久化线段树
To the moon Problem Description BackgroundTo The Moon is a independent game released in November 201 ...
- HDU 4348 To the moon 可持久化线段树,有时间戳的区间更新,区间求和
To the moonTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.a ...
- To the moon HDU - 4348 (主席树,区间修改)
Background To The Moon is a independent game released in November 2011, it is a role-playing adventu ...
随机推荐
- A - Mike and Cellphone
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was n ...
- python GUI尝鲜(但当涉猎,见往事耳)
第一步:简单的窗口和内容 import tkinter as tk window = tk.Tk() # 窗口obj对象 window.title('my TK') # 窗口名字 window.geo ...
- 【网络爬虫】【java】微博爬虫(三):庖丁解牛——HTML结构分析与正则切分
在上一篇文章中已经通过请求的url地址把html页面爬取下来了,这里分别以网易微博的html和新浪微博的html为例来分析如何提取微博数据. 一.网易微博解析 相比新浪微博的html结构,网易微博的比 ...
- 渲染路径-u3d渲染路径比较
Unity支持不同的渲染路径.应具体取决于你的游戏内容和目标平台/硬件来选择使用哪一个.不同的渲染路径有不同的特点和性能特点,主要影响灯光和阴影. 项目所使用的渲染路径在Player S ...
- unity3d 在UGUI中制作自适应调整大小的滚动布局控件
http://blog.csdn.net/rcfalcon/article/details/43459387 在游戏中,我们很多地方需要用到scroll content的概念:我们需要一个容器,能够指 ...
- Bloomberg 的一些功能
FFLO: 查看ETF流动,注意在View点击Contries后选择Asia,查看亚洲流动. 随后对感兴趣的国家点击查看具体股票的流动 关闭Launchpad View之后再次打开: BLP 修改La ...
- JDK 重要目录结构
\bin 目录包含 Java 的开发工具,包括 Java 编译器 javac.exe.Java 解释器 java.exe 等: javac:Java 编译器,用来将 Java 程序编译成字节码 jav ...
- 从图(Graph)到图卷积(Graph Convolution):漫谈图神经网络模型 (一)
本文属于图神经网络的系列文章,文章目录如下: 从图(Graph)到图卷积(Graph Convolution):漫谈图神经网络模型 (一) 从图(Graph)到图卷积(Graph Convolutio ...
- swipe轮播插件零基础实用
此篇博客整理了常用的轮播效果,适用于所有开发人员 swipe是当下相对而言较好用的轮播插件,下面是博主整理的demo源代码,可直接上手(备注:需自己手动swipe所需的j和css) 此段代码总共是有三 ...
- Log4j2 - java.lang.NoSuchMethodError: com.lmax.disruptor.dsl.Disruptor
问题 项目使用了log4j2,由于使用了全局异步打印日志的方式,还需要引入disruptor的依赖,最后使用的log4j2和disruptor的版本依赖如下: <dependency> & ...