POJ 3468
来源:互联网 发布:ubuntu tar 压缩 tgz 编辑:程序博客网 时间:2024/06/16 02:42
现在勉强能手打区间更新,Hotel 还是没学会
#include<stdio.h>#include<stdlib.h>#include<algorithm>#include<math.h>#include<string.h>//#include<queue>//#include<vector>//#include<set>using namespace std;#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))#define rel(i,n) for(int (i)=1;(i)<=(int)(n);++(i))#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define delf int m=(l+r)>>1#define LL long long//static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;//const int MAXN=1e4+5;const int MOD=1e9+7;const int MAXNODES=100005;//typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long LL;LL lazy[MAXNODES<<2];LL sum[MAXNODES<<2];void pushup(int rt){ sum[rt]=(sum[rt<<1]+sum[(rt<<1)|1]);}void pushdown(LL rt,LL m){ if(lazy[rt]) { lazy[rt<<1]+=lazy[rt]; lazy[rt<<1|1]+=lazy[rt]; sum[rt<<1]+=(m-(m>>1))*lazy[rt]; sum[rt<<1|1]+=(m>>1)*lazy[rt]; lazy[rt]=0; }}void build(LL l,LL r,LL rt){ lazy[rt]=0; if(l==r) { scanf("%I64d",&sum[rt]); return; } delf; build(lson); build(rson); pushup(rt);}void update(LL L,LL R,LL c,LL l,LL r,LL rt){ if(L<=l&&r<=R) { lazy[rt]+=c; sum[rt]+=c*(r-l+1); return; } pushdown(rt,r-l+1); delf; if(L<=m) update(L,R,c,lson); if(R>m) update(L,R,c,rson); pushup(rt);}LL query(LL L,LL R,LL l,LL r,LL rt){ if(L<=l&&r<=R) return sum[rt]; pushdown(rt,r-l+1); delf; LL ret=0; if(L<=m) ret+=query(L,R,lson); if(R>m) ret+=query(L,R,rson); return ret;}int main(){ //freopen("test.txt","r",stdin); int n,q; char tmp; LL a,b,c; memset(lazy,0,sizeof(lazy)); memset(sum,0,sizeof(sum)); scanf("%d%d",&n,&q); build(1,n,1); while(q--) { scanf("%*c%c",&tmp); if(tmp=='Q') { scanf("%I64d%I64d",&a,&b); printf("%I64d\n",query(a,b,1,n,1)); } else { scanf("%I64d%I64d%I64d",&a,&b,&c); update(a,b,c,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
- 句子逆序,带输入输出
- 高德地图的No implementation found for 问题解决
- Android 一站式打包(一)gradle 动态配置多环境
- 编译警告级别之重要性
- 13.Linux:使用DNW (原创)
- POJ 3468
- Java对象创建(含静态属性)内存分配流程解析
- int、long转换为float、double的区别
- 剖析七层
- 菜单
- JAVA虚拟机入门(2)------ 类加载机制(中)
- Pascal's Triangle帕斯卡三角形算法
- KMP讲解
- C、C++和VC++之间的区别