/*
裸题
*/
#include<stdio.h>
#include<string.h>
#define N 50000+10
struct node
{
int l,r,sum;
}Tree[3*N];
int a[N];
void build(int l,int r,int root)
{
Tree[root].l=l;
Tree[root].r=r;
if(l==r)
{
Tree[root].sum=a[l];
return ;
}
int mid=(l+r)>>1;
build(l,mid,2*root);
build(mid+1,r,2*root+1);
Tree[root].sum=(Tree[2*root].sum+Tree[2*root+1].sum);
}
int query(int l,int r,int root)
{
if(l==Tree[root].l && r==Tree[root].r)
{
return Tree[root].sum;
}
int mid=(Tree[root].l+Tree[root].r)>>1;
if(r<=mid)
{
query(l,r,2*root);
}
else if(l>mid)
{
query(l,r,2*root+1);
}
else
{
return query(l,mid,2*root)+ query(mid+1,r,2*root+1);
}
}
void update(int l,int r,int changenumber,int root)
{
Tree[root].sum+=changenumber;
if(Tree[root].l==l && Tree[root].r==r)
{
return ;
}
int mid=(Tree[root].l+Tree[root].r)>>1;
if(r<=mid)
update(l,r,changenumber,2*root);
else if(l>mid)
update(l,r,changenumber,2*root+1);
else
{
update(l,mid,changenumber,2*root);
update(mid+1,r,changenumber,2*root+1);
}
Tree[root].sum=Tree[2*root].sum+Tree[2*root+1].sum;
}
int main()
{
int t,n,x,y;
char str[20];
scanf("%d",&t);
//while(t--)
for(int Case=1;Case<=t;Case++)
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
printf("Case %d:\n",Case);
build(1,n,1);
getchar();
while(scanf("%s",str))
{
if(strcmp(str,"End")==0)
break;
scanf("%d%d",&x,&y);
if(str[0]=='Q')
{
printf("%d\n",query(x,y,1));
}
else if(str[0]=='A')
{
update(x,x,y,1);
}
else
{
update(x,x,-y,1);
}
}
}
return 0;
}
#include<stdio.h>
#include<string.h>
#define maxn 50001
int a[maxn];
int lowbit(int x)
{
return (x&(-x));
}
void updata(int x,int y)
{
int i;
for(i=x;i<maxn;i+=lowbit(i))
a[i]+=y;
}
int getsum(int x)
{
int sum=0,i;
for(i=x;i>0;i-=lowbit(i))
sum+=a[i];
return sum;
}
int main()
{
char chars[10];
int t,x,y,i,n,k,j;
scanf("%d",&t);
for(j=1;j<=t;j++)
{
memset(a,0,sizeof(a));
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&k);
updata(i,k);
}
printf ("Case %d:\n", j) ;
while(scanf("%s",chars))
{
if(chars[0]=='E')
break;
else if(chars[0]=='A')
{
scanf("%d%d",&x,&y); //第x增加y人
updata(x,y);
}
else if(chars[0]=='S')
{
scanf("%d%d",&x,&y);
updata(x,-y);
}
else
{
scanf("%d%d",&x,&y);
printf("%d\n",getsum(y)-getsum(x-1));
}
}
}
return 0;
}