2011-05-13 22:02:17 题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1166 树状数组:http://baike.baidu.com/view/1420784.htm #include<stdio.h> #define N 50005 int a[N],n; void Add(int i,int j) { while (i<=n) { a[i]+=j; i+=i&(-i); } } int Sum(int j) { int ret=0; while (j>0) { ret+=a[j]; j-=j&(-j); } return ret; } int main() { int t,i,j,test=0,sum,temp; char str[10]; scanf("%d",&t); while (t--) { test++; scanf("%d",&n); for(i=0;i<n;i++) a[i]=0; for(i=1;i<=n;i++) { scanf("%d",&temp); Add(i,temp); } printf("Case %d:/n",test); while (~scanf("%s",str)&&str[0]!='E') { if(str[0]!='Q') { scanf("%d%d",&i,&j); if(str[0]=='A') Add(i,j); else Add(i,-j); } else { scanf("%d%d",&i,&j); sum=Sum(j)-Sum(i-1); printf("%d/n",sum); } } } return 0; }