Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 76442 Accepted Submission(s):
32168
1 #include <cstdio> 2 #include <cmath> 3 #include <cstring> 4 #include <cstdlib> 5 #include <queue> 6 #include <stack> 7 #include <vector> 8 #include <iostream> 9 #include "algorithm" 10 using namespace std; 11 typedef long long LL; 12 const int MAX=50005; 13 int t; 14 int n; 15 int s[MAX]; 16 void add(int x,int y){ 17 for (;x<=n;x+=(x&-x)) s[x]+=y; 18 } 19 int search(int x){ 20 int an(0); 21 for (;x>0;x-=(x&-x)) an+=s[x]; 22 return an; 23 } 24 char read1(){ 25 char x; 26 x=getchar(); 27 while (x<‘A‘ || x>‘Z‘) x=getchar(); 28 return x; 29 } 30 int read(){ 31 char x; 32 int an(0); 33 x=getchar(); 34 while (x<‘0‘ || x>‘9‘) x=getchar(); 35 while (x>=‘0‘ && x<=‘9‘){an=an*10+x-‘0‘;x=getchar();} 36 return an; 37 } 38 void out(int x){ 39 if (x<10) 40 {putchar(x+‘0‘); 41 return; 42 } 43 out(x/10); 44 putchar(x%10+‘0‘); 45 } 46 void init(){ 47 int i,j; 48 n=read(); 49 memset(s,0,sizeof(s)); 50 for (i=1;i<=n;i++) 51 {j=read(); 52 add(i,j); 53 } 54 } 55 int main(){ 56 int i,j;char c; 57 int zt(0); 58 scanf("%d\n",&t); 59 while (t--){ 60 init(); 61 printf("Case %d:\n",++zt); 62 while (1) 63 {c=read1(); 64 if (c==‘E‘) 65 break; 66 i=read(); 67 j=read(); 68 if (c==‘A‘) 69 add(i,j); 70 if (c==‘S‘) 71 add(i,-j); 72 if (c==‘Q‘) 73 {out(search(j)-search(i-1)); 74 putchar(‘\n‘); 75 } 76 } 77 } 78 return 0; 79 }
原文:http://www.cnblogs.com/Michaelzzn/p/5740826.html