#define LL(x) ((x)<<1)
#define RR(x) ((x)<<1|1)
#define FF(i,n) for(int i = 0 ; i < n ; i ++)
1 struct Seg_Tree{
2 int left,right,num;
3 int calmid() {
4 return (left+right)/2;
5 }
6 }tt[150000];
7 int num[50001];
8 int build(int left,int right,int idx) {
9 tt[idx].left = left;
10 tt[idx].right = right;
11 if(left == right) {
12 return tt[idx].num = num[left];
13 }
14 int mid = (left + right)/2;
15 return tt[idx].num = build(left,mid,LL(idx)) + build(mid+1,right,RR(idx));
16 }
17
18 void update(int id,int x,int idx) {
19 tt[idx].num += x;
20 if(tt[idx].left == tt[idx].right) {
21 return ;
22 }
23 int mid = tt[idx].calmid();
24 if(id <= mid) {
25 update(id,x,LL(idx));
26 } else {
27 update(id,x,RR(idx));
28 }
29 }
30
31 int query(int left,int right,int idx) {
32 if(left == tt[idx].left && right == tt[idx].right) {
33 return tt[idx].num;
34 }
35 int mid = tt[idx].calmid();
36 if(right <= mid) {
37 return query(left,right,LL(idx));
38 } else if(mid < left) {
39 return query(left,right,RR(idx));
40 } else {
41 return query(left,mid,LL(idx)) + query(mid+1,right,RR(idx));
42 }
43 }
44
45 int main() {
46 int T;
47 scanf(“%d”,T);
48 FF(cas,T) {
49 int n;
50 scanf(“%d”,&n);
51 FOR(i,1,1+n) {
52 scanf(“%d”,num[i]);
53 }
54 build(1,n,1);
55 printf("Case %d:\n",cas+1);
56 char com[9];
57 while(scanf("%s",com)) {
58 if(strcmp(com,"End") == 0) break;
59 int a,b;
60 scanf("%d%d",&a,&b);
61 switch(com[0]) {
62 case 'Q':
63 printf("%d\n",query(a,b,1));
64 break;
65 case 'A':
66 update(a,b,1);
67 break;
68 case 'S':
69 update(a,-b,1);
70 break;
71 }
72 }
73 }
74 return 0;
75 }