poj 3468
来源:互联网 发布:苹果性能测试软件 编辑:程序博客网 时间:2024/06/04 18:29
# include <stdio.h># define lson l,m,rt<<1# define rson m+1,r,rt<<1|1# define maxn 100009__int64 sum[maxn<<2],col[maxn<<2];void Pushup(int rt){ sum[rt]=sum[rt<<1]+sum[rt<<1|1];}void build(int l,int r,int rt){ col[rt]=0; if(l==r){ scanf("%I64d",&sum[rt]);return ; } int m=(l+r)>>1; build(lson); build(rson); Pushup(rt);}void Pushdown(int rt,int m){ if(col[rt]!=0){ col[rt<<1]+=col[rt]; col[rt<<1|1]+=col[rt]; sum[rt<<1]+=(m-(m>>1))*col[rt]; sum[rt<<1|1]+=(m>>1)*col[rt]; col[rt]=0; }}void add(int L,int R,int c,int l,int r,int rt){ if(L<=l&&r<=R){ col[rt]+=c; sum[rt]+=(r-l+1)*c; return ; } Pushdown(rt,r-l+1); int m=(l+r)>>1; if(L<=m) add(L,R,c,lson); if(R>m) add(L,R,c,rson); Pushup(rt);}__int64 query(int L,int R,int l,int r,int rt){ if(L<=l&&r<=R){ return sum[rt]; } Pushdown(rt,r-l+1); __int64 ret=0; int m=(l+r)>>1; if(L<=m) ret+=query(L,R,lson); if(R>m) ret+=query(L,R,rson); return ret;}int main (){ int n,m,a,b,c; scanf("%d%d",&n,&m); build(1,n,1); char s[10]; for(int i=1;i<=m;i++){ scanf("%s",s); if(s[0]=='C'){ scanf("%d%d%d",&a,&b,&c); add(a,b,c,1,n,1); } if(s[0]=='Q'){ scanf("%d%d",&a,&b); printf("%I64d\n",query(a,b,1,n,1)); } } return 0;}………………………………稀里糊涂的就过了
0 0
- poj 3468
- POJ 3468
- poj 3468
- poj 3468
- poj 3468
- poj 3468
- poj 3468
- POJ 3468
- POJ 3468
- POJ 3468
- POJ 3468
- POJ 3468
- poj 3468
- poj-3468
- POJ 3468
- POJ 3468
- POJ-3468
- poj 3468
- 无法回忆的等待
- Java基础回顾_Java for循环运行步骤Code详解
- SRM 620 D2L3: RandomGraph, dp
- 35 Practical Examples of Linux Find Command
- 三层架构与四大天王之——删
- poj 3468
- SDP协议
- scrapy配置过程遇到的问题以及解决--001
- 国外怎么看世界杯win7系统怎么设置VPN怎么看CCTV5巴西世界杯直播
- Eclipse SDK中一些插件的安装(web开发插件)
- mysql数据仓库指南
- 中国天气网天气图例
- UVa 10041 - Vito's Family
- acdream Number theory