1 #include2 #include 3 #define MAXN 50010 4 int tree[MAXN<<2]; 5 inline void PushUp(int rt) 6 { 7 tree[rt]=tree[rt<<1]+tree[rt<<1|1]; 8 } 9 void Build(int L,int R,int rt)10 {11 if(L==R)12 scanf("%d",&tree[rt]);13 else14 {15 int mid=(L+R)>>1;16 Build(L,mid,rt<<1);17 Build(mid+1,R,rt<<1|1);18 PushUp(rt);19 }20 }21 void Update(int x,int val,int L,int R,int rt)22 {23 if(L==R)24 tree[rt]+=val;25 else26 {27 int mid=(L+R)>>1;28 if(x<=mid)29 Update(x,val,L,mid,rt<<1);30 else31 Update(x,val,mid+1,R,rt<<1|1);32 PushUp(rt);33 }34 }35 int Query(int x,int y,int L,int R,int rt)36 {37 if(x<=L&&R<=y)38 return tree[rt];39 int mid,ans;40 mid=(L+R)>>1;41 ans=0;42 if(mid>=x)43 ans+=Query(x,y,L,mid,rt<<1);44 if(mid