本题按照题意来即可,别人的代码
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn=50000+10;
struct node{
int L,R,sum;
int mid(){//计算中间值
return (L+R)/2;
}
}tree[maxn*4];
int val[maxn];
void build(int root,int L,int R)
{
tree[root].L=L,tree[root].R=R;
if(L==R)
{
tree[root].sum=val[L];
return;
}
build(root<<1,L,tree[root].mid());
build(root<<1|1,tree[root].mid()+1,R);
tree[root].sum=tree[root<<1].sum+tree[root<<1|1].sum;
}
void Insert(int root,int k,int e)
{
tree[root].sum+=e;
if(tree[root].L==tree[root].R)
return;
if(k<=tree[root].mid())
Insert(root<<1,k,e);
else
Insert(root<<1|1,k,e);
}
int Query(int root,int L,int R)
{
if(tree[root].L==L&&tree[root].R==R)
return tree[root].sum;
if(R<=tree[root].mid())
return Query(root<<1,L,R);
else if(L>tree[root].mid())
return Query(root<<1|1,L,R);
else
{
int Lsum=Query(root<<1,L,tree[root].mid());
int Rsum=Query(root<<1|1,tree[root].mid()+1,R);
return Lsum+Rsum;
}
}
int main()
{
int T,t=1;
int n,x,y;
//freopen("A.txt","r",stdin);
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&val[i]);
build(1,1,n);
char s[10];
printf("Case %d:\n",t++);
while(scanf("%s",s),s[0]!='E')
{
scanf("%d %d",&x,&y);
if(s[0]=='A') Insert(1,x,y);
else if(s[0]=='S') Insert(1,x,-y);
else
{
int ans=Query(1,x,y);
printf("%d\n",ans);
}
}
}
}