A –
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
SubmitStatusPracticeHDU 1166
Description
CACDerekTidyAN,DerekTidyC,,C
,TidyDerek,Derek:Tidy,310!TidyDerekTidyDerekTidy:”!Tidy!!TidyWindbreaker,Windbreakeracm!Tidy””WindbreakerTidyTidyDerek.

Input
TT
NN<=50000,NN,iaiiai1<=ai<=50 4 (1) Add i j,ij,ijj30 (2)Sub i j ,ij,ijj30; (3)Query i j ,ij,i<=jij; (4)End ; 40000 Output i,Case i:, Query,,1000000 Sample Input 1 10 1 2 3 4 5 6 7 8 9 10 Query 1 3 Add 3 6 Query 2 7 Sub 10 2 Add 6 3 Query 3 10 End Sample Output Case 1: 6 33 59

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <cstdio>
#include <cstring>
#include <cstdio>
#include <string>
#include <iostream>
 
using namespace std;
 
char com[100];
int a[50010];
int n;
 
struct Node{
    int l, r, v;
}tree[200010];
 
void Build(int pos, int l, int r){
    tree[pos].l = l;
    tree[pos].r = r;
    if(l == r){
        tree[pos].v = a[tree[pos].l];
        return ;
    }
    int mid = (l + r) / 2;
    Build(pos * 2, l, mid);
    Build(pos * 2 + 1, mid + 1, r);
    tree[pos].v = tree[pos * 2].v + tree[pos * 2 + 1].v;
}
 
void Update(int pos, int idx, int val){
    if(tree[pos].l == tree[pos].r){
        tree[pos].v += val;
        return ;
    }
    int mid = (tree[pos].l + tree[pos].r) / 2;
    if(idx <= mid)
        Update(pos * 2, idx, val);
    else
        Update(pos * 2 + 1, idx, val);
    tree[pos].v = tree[pos * 2].v + tree[pos * 2 + 1].v;
}
 
int Query(int pos, int l, int r){
    if(l <= tree[pos].l && tree[pos].r <= r){
        return tree[pos].v;
    }
    int ret = 0, mid = (tree[pos].l + tree[pos].r) / 2;
    if(l <= mid)
        ret += Query(pos * 2, l, r);
    if(r > mid)
        ret += Query(pos * 2 + 1, l, r);
    return ret;
}
 
int main(){
    int t;
    int x, y, i, j, k;
    int cnt = 0;
    scanf("%d", &t);
    while(t --){
        cnt ++;
        scanf("%d", &n);
        printf("Case %d:\n", cnt);
        for(i = 1; i <= n; i++){
            scanf("%d", &a[i]);
        }
        Build(1, 1, n);
        while(scanf ("%s", com)){
            if(com[0] == 'E')
                break;
            else if(com[0] == 'Q'){
                scanf("%d%d", &x, &y);
                printf("%d\n", Query(1, x, y));
            }
            else if(com[0] == 'A'){
                scanf("%d%d", &x, &y);
                Update(1, x, y);
            }
            else if(com[0] == 'S'){
                scanf("%d%d", &x, &y);
                Update(1, x, -y);
            }
        }
    }
    return 0;
}