hdu1166(敌兵布阵)

#include <iostream>
#include <cstdio>
int n,c[50010];
int lowbit(int x){
   return x&(-x);
}

int sum(int x){
   int s=0;
   while(x>0){
      s += c[x];
      x -= lowbit(x);
   }
   return s;
}

void update(int x, int val){ //Cow
   while(x<=n){
      c[x] += val;
      x += lowbit(x);
   }
}

int main(){
   int T,t,i,tem;
   scanf("%d",&T);
   for(t=1;t<=T;t++){
      printf("Case %d:\n",t);
      scanf("%d",&n);
      memset(c,0,sizeof(c));
      for(i=1;i<=n;i++){
         scanf("%d",&tem);
         update(i,tem);
      }
      char m[10];
      while(scanf("%s", m)){
         if(m[0]=='E') // End
            break;
         if(m[0]=='A'){   //Add
            int p, q;
            scanf("%d%d",&p, &q);
            update(p, q);
         }
         if(m[0]=='S'){  //Sub
            int p, q;
            scanf("%d %d",&p,&q);
            update(p,-q);
         }
         if(m[0]=='Q'){  //Query
            int p,q;
               scanf("%d %d",&p, &q);
            if(p==1)
               printf("%d\n",sum(q));
            else
               printf("%d\n",sum(q)-sum(p-1));
         }
      }
   }
}
//http://blog.csdn.net/waitfor_/article/category/912651

你可能感兴趣的:(c,include)