标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 76810 Accepted Submission(s): 32363
#include <cstdio> #include <algorithm> #define lson l,m,rt<<1 #define rson m+1,r,rt<< 1 | 1 using namespace std; int sum[201000]; void PushUp(int rt){ sum[rt]=sum[rt<<1]+sum[rt<<1 |1]; } void build(int l,int r,int rt){ if(l==r){ scanf("%d",sum+rt); return; } int m=(l+r)>>1; build(lson); build(rson); PushUp(rt); } void update(int p ,int sc,int l,int r,int rt){ if(l==r){ sum[rt]+=sc; return; } int m= (l+r)>>1; if(p<=m) update(p,sc,lson); else update(p,sc,rson); PushUp(rt); } int query(int L,int R,int l,int r,int rt){ if(L>r||l>R) return 0; if(l>=L&&r<=R) return sum[rt]; int m=(l+r)>> 1; int s1=query(L,R,lson); int s2=query(L,R,rson); return s1+s2; } int main(){ //freopen("data.in","r",stdin); int n,t; scanf("%d",&t); for(int z=1;z<=t;z++){ printf("Case %d:\n",z); scanf("%d",&n); build(1,n,1); char s[10];int a,b; while(scanf("%s",s),s[0]!=‘E‘){ scanf("%d%d",&a,&b); if(s[0]==‘Q‘) printf("%d\n",query(a,b,1,n,1)); else{ if(s[0]==‘A‘) update(a,b,1,n,1); else update(a,-b,1,n,1); } } } }
标签:
原文地址:http://www.cnblogs.com/acmtime/p/5751152.html