/*
分析:
以前用线段树写过了,现在会了树状数组,就又写了个。
不过这个没有线段树效率高呀,至少我写的,对于这个题来说,
线段树的那个代码更快点儿。
2012-09-16
*/
分析:
以前用线段树写过了,现在会了树状数组,就又写了个。
不过这个没有线段树效率高呀,至少我写的,对于这个题来说,
线段树的那个代码更快点儿。
2012-09-16
*/
#include"stdio.h"
#include"string.h"
int n;
int C[50011];
void add(int k,int dir)
{
while(k<=n)
{
C[k]+=dir;
k+=k&(-k);
}
}
int query(int k)
{
int t=0;
while(k>0)
{
t+=C[k];
k-=k&(-k);
}
return t;
}
int main()
{
int T,Case;
int i;
int a,b;
int temp;
char str[22];
scanf("%d",&T);
for(Case=1;Case<=T;Case++)
{
scanf("%d",&n);
memset(C,0,sizeof(C));
for(i=1;i<=n;i++)
{
scanf("%d",&temp);
add(i,temp);
}
printf("Case %d:\n",Case);
while(scanf("%s",str),strcmp(str,"End"))
{
if(strcmp(str,"Query")==0)
{
scanf("%d%d",&a,&b);
printf("%d\n",query(b)-query(a-1));
}
else if(strcmp(str,"Add")==0)
{
scanf("%d%d",&a,&b);
add(a,b);
}
else
{
scanf("%d%d",&a,&b);
add(a,-b);
}
}
}
return 0;
}