题解:

因为卡空间,所以直接到spoj上面去做了

区间修改的线段树

但是加lazy会把之前的操作修改

正确的解法是lazy不下传,只是在当前计算

但是听说可以记录时间的下传,我弱弱不会

代码:

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
typedef long long ll;
struct aa
{
int lc,rc,l,r;
ll add,sum;
int len(){return r-l+;}
}a[N*];
int n,m,rt[N],time,tot,Time[N];
void build(int &u,int l,int r)
{
u=++tot;
a[u].l=l,a[u].r=r;
if (l==r) {scanf("%lld",&a[u].sum);return;}
int mid=(l+r)>>;
build(a[u].lc,l,mid);
build(a[u].rc,mid+,r);
a[u].sum=a[a[u].lc].sum+a[a[u].rc].sum;
}
void insert(int &now,int old,int l,int r,ll d)
{
now=++tot;
a[now]=a[old];
if (a[old].l==l&&a[old].r==r)
{
a[now].add+=d;
return;
}
a[now].sum+=d*(r-l+);
int mid=(a[now].l+a[now].r)>>;
if (r<=mid) insert(a[now].lc,a[old].lc,l,r,d);
else if (mid<l) insert(a[now].rc,a[old].rc,l,r,d);
else
{
insert(a[now].lc,a[old].lc,l,mid,d);
insert(a[now].rc,a[old].rc,mid+,r,d);
}
}
ll query(int u,int l,int r)
{
ll tmp=a[u].add*(r-l+);
if (a[u].l==l&&a[u].r==r) return a[u].sum+tmp;
int mid=(a[u].l+a[u].r)>>;
if (r<=mid) return tmp+query(a[u].lc,l,r);
else if (mid<l) return tmp+query(a[u].rc,l,r);
return tmp+query(a[u].lc,l,mid)+query(a[u].rc,mid+,r);
}
int main()
{
scanf("%d%d",&n,&m);
build(rt[],,n);
time=;
char ch[];
int x,y,t;ll d;
for (int i=;i<=m;i++)
{
scanf("%s",ch);
if (ch[]=='C')
{
scanf("%d%d%lld",&x,&y,&d);
time++;
insert(rt[time],rt[time-],x,y,d);
Time[time]=tot;
}
if (ch[]=='Q')
{
scanf("%d%d",&x,&y);
printf("%lld\n",query(rt[time],x,y));
}
if (ch[]=='H')
{
scanf("%d%d%d",&x,&y,&t);
printf("%lld\n",query(rt[t],x,y));
}
if (ch[]=='B')
{
scanf("%d",&time);
tot=Time[time];
}
}
return ;
}

最新文章

  1. 【CodeForces 614A】Link/Cut Tree
  2. [LintCode] Implement Trie 实现字典树
  3. 扎克伯格谈Facebook创业过程
  4. ubuntu下使用quick2wire控制RespberryPi2的I2C
  5. 【行业干货】ASOS:外来快时尚品牌的入华战 - 行业干货 - 京东内部论坛 - Powered by Discuz!
  6. linux 获取系统屏幕分辨率
  7. Jquery progressbar通过Ajax请求获取后台进度演示
  8. vc笔记六
  9. AOE 网络
  10. linux防火墙基本操作
  11. 移动端300ms的点击延迟以及解决方案
  12. [ZJOI2015]地震后的幻想乡
  13. 如何查找元素对应事件的js代码,检测定位js事件
  14. exists,in的区别-mysql
  15. 使用visual C++测试
  16. 使用参数innodb_file_per_table支持MySQL InnoDB表数据共享空间自动收缩
  17. mescroll在vue中的应用
  18. 阿里八八Alpha阶段Scrum(2/12)
  19. labview程序性能优化
  20. [翻译] ZFDragableModalTransition

热门文章

  1. 51NOD 1117 聪明的木匠
  2. eclipse 在线安装反编译插件
  3. 解决 mininet gave up after 3 retries 问题
  4. nohup 日志切割
  5. poj 2480 Longge&#39;s problem 欧拉函数+素数打表
  6. RobotFramework安装指南
  7. django字段的参数
  8. XML_CPP_资料_libXml2_01_Code_ZC(?.pro)
  9. Spring AMQP 源码分析 02 - CachingConnectionFactory
  10. flash破解工具/flash decompiler