标签:
1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 using namespace std; 5 6 int n,aa[50005],cc[50005]; 7 8 int lowbit(int x) 9 { 10 return x&(-x); 11 } 12 13 void add(int x,int y) 14 { 15 while(x<=n) 16 { 17 cc[x]+=y; 18 x+=lowbit(x); 19 } 20 } 21 22 int sum(int x) 23 { 24 int s=0; 25 while(x>0) 26 { 27 s+=cc[x]; 28 x-=lowbit(x); 29 } 30 return s; 31 } 32 33 int main() 34 { 35 int t,countn=1; 36 char str[20]; 37 scanf("%d",&t); 38 while(t--) 39 { 40 memset(aa,0,sizeof(aa)); 41 memset(cc,0,sizeof(cc)); 42 scanf("%d",&n); 43 for(int i=1;i<=n;i++) 44 { 45 scanf("%d",&aa[i]); 46 add(i,aa[i]); 47 } 48 printf("Case %d:\n",countn); 49 while(~scanf("%s",str)) 50 { 51 if(str[0]==‘E‘) 52 break; 53 if(str[0]==‘A‘) 54 { 55 int a,b; 56 scanf("%d%d",&a,&b); 57 add(a,b); 58 } 59 if(str[0]==‘Q‘) 60 { 61 int a,b; 62 scanf("%d%d",&a,&b); 63 printf("%d\n",sum(b)-sum(a-1)); 64 } 65 if(str[0]==‘S‘) 66 { 67 int a,b; 68 scanf("%d%d",&a,&b); 69 add(a,-b); 70 } 71 } 72 countn++; 73 } 74 return 0; 75 }
标签:
原文地址:http://www.cnblogs.com/wenbao/p/5694305.html