标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 57804 Accepted Submission(s): 24428
1 #include<stdio.h> 2 #include<string.h> 3 int n; 4 int c[250000]; 5 int lowbit(int x) 6 { 7 return x&(-x); 8 } 9 int sum(int n) 10 { 11 int sum=0; 12 while(n>0) 13 { 14 sum+=c[n]; 15 n-=lowbit(n); 16 } 17 return sum; 18 } 19 void change(int i,int x) 20 { 21 while(i<=n) 22 { 23 c[i]+=x; 24 i+=lowbit(i); 25 } 26 } 27 int main() 28 { 29 int i,j,k=0,t,m,T,x; 30 char s[25]; 31 scanf("%d",&T); 32 while(T--) 33 { 34 memset(c,0,sizeof(c)); 35 m=1; 36 scanf("%d",&n); 37 for(i=1;i<=n;i++) 38 { 39 scanf("%d",&x); 40 change(i,x); 41 } 42 getchar(); 43 printf("Case %d:\n",++k); 44 while(scanf("%s",&s)!=EOF) 45 { 46 if(s[0]==‘E‘) break; 47 if(s[0]==‘Q‘) 48 { 49 scanf("%d%d",&i,&j); 50 printf("%d\n",sum(j)-sum(i-1)); 51 } 52 else if(s[0]==‘A‘) 53 { 54 scanf("%d%d",&i,&j); 55 change(i,j); 56 } 57 else if(s[0]==‘S‘) 58 { 59 scanf("%d%d",&i,&j); 60 change(i,-j); 61 } 62 } 63 } 64 return 0; 65 }
标签:
原文地址:http://www.cnblogs.com/zero-zz/p/4699137.html