队友套的可持续化线段树,徘徊在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 可持续化的更多相关文章

  1. 【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| ...

  2. hdu 4348 To the moon (主席树)

    版权声明:本文为博主原创文章,未经博主允许不得转载. hdu 4348 题意: 一个长度为n的数组,4种操作 : (1)C l r d:区间[l,r]中的数都加1,同时当前的时间戳加1 . (2)Q ...

  3. 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 ...

  4. 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    询问当前时 ...

  5. HDU 4348 To the moon 主席树 在线更新

    http://acm.hdu.edu.cn/showproblem.php?pid=4348 以前做的主席树没有做过在线修改的题做一下(主席树这种东西正经用法难道不是在线修改吗),标记永久化比较方便. ...

  6. HDU 4348 SPOJ 11470 To the moon

    Vjudge题面 Time limit 2000 ms Memory limit 65536 kB OS Windows Source 2012 Multi-University Training C ...

  7. HDU 4348 To the moon 可持久化线段树

    To the moon Problem Description BackgroundTo The Moon is a independent game released in November 201 ...

  8. HDU 4348 To the moon 可持久化线段树,有时间戳的区间更新,区间求和

    To the moonTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.a ...

  9. To the moon HDU - 4348 (主席树,区间修改)

    Background To The Moon is a independent game released in November 2011, it is a role-playing adventu ...

随机推荐

  1. 技术胖Flutter第四季-19导航父子页面的跳转返回

    技术胖Flutter第四季-19导航父子页面的跳转返回 博客地址: https://jspang.com/post/flutter4.html#toc-010 onPressed是当前按下的时候,按下 ...

  2. Flutter实战视频-移动电商-17.首页_楼层组件的编写技巧

    17.首页_楼层组件的编写技巧 博客地址: https://jspang.com/post/FlutterShop.html#toc-b50 楼层的效果: 标题 stlessW快速生成: 接收一个St ...

  3. Junit使用注意点

    注意点 1. 使用了@BeforeClass后@Ignore将会失效

  4. iOS 中使用 MJExtension 遇到 关键字(id) 怎么办

    MJExtension 是个人比较喜欢用的json 转model 的软件,当遇到系统关键字时就会出现崩溃,解决方式如下 1.建立Modle 解析类,服务返回数据中带有id,这个时候用字典转Mode(m ...

  5. 1004 Counting Leaves (30 分)

    A family hierarchy is usually presented by a pedigree tree. Your job is to count those family member ...

  6. 数据结构关于AOV与AOE网的区别

    AOV网,顶点表示活动,弧表示活动间的优先关系的有向图. 即如果a->b,那么a是b的先决条件. AOE网,边表示活动,是一个带权的有向无环图, 其中顶点表示事件,弧表示活动,权表示活动持续时间 ...

  7. Unity亚洲开发者大会会议简录之技术篇,Profiler的一些参数的意思

    2014Unity亚洲开发者大会会议简录之技术篇 拖公司的福,有幸去了一趟北京参加了一场Unity3D的交流盛宴,在为期两天的时间内,不仅有着技术上收获,也有心灵上的震撼.现在先来说说技术方面的一些比 ...

  8. PJzhang:互联网是有国界

    猫宁!!! 参考链接:https://mp.weixin.qq.com/s/NFgps_5HBpl3ZjDoR5w8XA 上世纪90年代,互联网开始崛起,美国凭借超级大国的地位,先进技术优势,以美国公 ...

  9. 测试 | Mock object

    实例: 一个简单的图书管理系统包括三个类: Book提供了书籍的定义 BookService提供了有关书籍借阅和归还的服务 BookMananger查找书籍并把对书籍状态的更改更新到数据库中 目前,B ...

  10. iOS 同一个View识别单击和双击手势

    1.给View添加手势 //view添加两个手势检测方法 self.currentPlayerView.userInteractionEnabled = YES; UITapGestureRecogn ...