poj 3468 A Simple Problem with Integers
来源:互联网 发布:python 2.7.11 编辑:程序博客网 时间:2024/04/29 11:45
区间成段更新的问题,虽然明白了,但是却感觉写不出什么东西来,还是得多做点题加深感悟
#include <iostream>#include <fstream>#include <cstdio>#include <algorithm>#include <cstring>#include <string>#include <string.h>#include <vector>#include <bitset>#include <cmath>#include <queue>#include <stack>#include <set>#include <ctime>#include <map>#include <limits>#define LL long long#define Vi vector<int>#define Si set<int>#define readf freopen("input.txt","r",stdin)#define writef freopen("output.txt","w",stdout)#define FF(i,a) for(int i(0); i < (a); i++)#define FD(i,a) for(int i(a); i >= (1); i--)#define FOR(i,a,b) for(int i(a);i <= (b); i++)#define FOD(i,a,b) for(int i(a);i >= (b); i--)#define PD(a) printf("%d",a)#define SET(a,b) memset(a,b,sizeof(a))#define SD(a) scanf("%d",&(a))#define LN printf("\n")#define PS printf(" ")#define pb push_back#define lson l , m , rt << 1#define rson m + 1 , r , rt << 1 | 1const double pi = acos(-1.0);const int maxn = 100001;const int INF = 99999999;const int dx[]={0,1,0,-1};const int dy[]={1,0,-1,0};using namespace std;LL col[maxn<<2],sum[maxn<<2];void PushUP(int rt){ sum[rt]=sum[rt<<1]+sum[rt<<1|1];}void PushDown(int rt,int len){ if(col[rt]){ col[rt<<1]+=col[rt]; col[rt<<1|1]+=col[rt]; sum[rt<<1]+=(len-(len>>1))*col[rt]; sum[rt<<1|1]+=(len>>1)*col[rt]; col[rt]=0; }}void build(int l,int r,int rt){ col[rt]=0; if(l==r){ scanf("%lld",&sum[rt]); return ; } int m=(l+r)>>1; build(lson); build(rson); PushUP(rt);}void update(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) update(L,R,c,lson); if( R>m) update(L,R,c,rson); PushUP(rt);}LL query(int L,int R,int l,int r,int rt){ if(L<= l && R>=r){ return sum[rt]; } PushDown(rt,r-l+1); int m=(l+r)>>1; LL ret=0; if(L<=m) ret+=query(L,R,lson); if(R> m) ret+=query(L,R,rson); return ret;}int main(){ int N,M; SD(N),SD(M); build(1,N,1); while(M--){ char op[5]; scanf("%s",op); int L,R,c; if(op[0]=='Q'){ scanf("%d%d",&L,&R); printf("%lld\n",query(L,R,1,N,1)); }else{ scanf("%d%d%d",&L,&R,&c); update(L,R,c,1,N,1); } }}
- POJ 3468 A Simple Problem With Integers
- poj 3468 A Simple Problem with Integers
- poj 3468 A Simple Problem with Integers
- POJ 3468 A Simple Problem with Integers
- poj 3468 A Simple Problem with Integers
- poj 3468 A Simple Problem with Integers
- poj 3468 A Simple Problem with Integers
- poj 3468 A Simple Problem with Integers
- POJ-3468-A Simple Problem with Integers
- POJ 3468 A Simple Problem with Integers
- poj 3468 A Simple Problem with Integers
- POJ 3468 - A Simple Problem with Integers
- poj 3468 A Simple Problem with Integers
- poj 3468 A Simple Problem with Integers
- POJ 3468 A Simple Problem with Integers
- poj 3468 A Simple Problem with Integers
- POJ 3468 A Simple Problem with Integers
- poj 3468 A Simple Problem with Integers
- 好想牵一次你的手 - Qzone日志
- Js实现多张图片有规律的随机切换
- C#与.NET4.0中WCF章节-未解决程序问题
- 有点失落
- 操作系统——文件管理
- poj 3468 A Simple Problem with Integers
- Dijkstra最短路径求解(不考虑权值为负的情况)
- MySQL关联left join 条件on与where不同
- 产品经理常犯的七大错误
- 毕业设计---android客户端2
- 笔记:Gof设计模式--Iterator
- 某书——数据访问技术的发展,以及ado.net
- Java文件读写操作大全
- html总结概要