//250ms
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define low(x) x&(-x)
int c[50005],n;
void add(int i,int val)
{
while(i<=n)
{
c[i]+=val;
i+=low(i);
}
}
int getsum(int i)
{
int sum=0;
while(i>0)
{
sum+=c[i];
i-=low(i);
}
return sum;
}
int main()
{
int t,i,k=1;
cin>>t;
while(t--)
{
printf("Case %d:\n",k++);
scanf("%d",&n);
c[0]=0;
int w;
memset(c,0,sizeof(c));
for(i=1;i<=n;i++)
{
scanf("%d",&w);
add(i,w);
}
char a[10];
while(scanf("%s",a)!=EOF&&strcmp(a,"End")!=0)
{
int x,y;
cin>>x>>y;
if(a[0]=='A')add(x,y);
else if(a[0]=='S')add(x,-y);
else printf("%d\n",getsum(y)-getsum(x-1));
//for(i=1;i<=n;i++)printf("%d %d %d\n",i,c[i],getsum(i));
}
}
return 0;
}
hdu1166 (树状数组 简单题)
最新推荐文章于 2019-09-06 21:56:29 发布