-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext.cpp
65 lines (64 loc) · 1.54 KB
/
text.cpp
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
/*************************************************************************
> File Name: text.cpp
> Author: heheql
> Mail: [email protected]
> Created Time: 2017年09月09日 星期六 23时21分47秒
************************************************************************/
#include <iostream>
#include <algorithm>
#define lson l, m, rt<<1
#define rson m+1,r, rt<<1|1
using namespace std;
const int maxn = 50010;
int sum[maxn << 2];
void build(int l, int r, int rt){
if(r==l){
cin >> sum[rt];
return ;
}
int m = (l+r) >> 1;
build(lson);
build(rson);
sum[rt] = sum[rt<<1] + sum[rt<<1|1];
}
int query(int s, int e, int l, int r, int rt){
if(s<=l&&r<=e){
return sum[rt];
}
int m = (l+r)>>1;
int ans = 0;
if(l<=m) ans += query(s,e,lson);
if(m<r) ans += query(s,e,rson);
return ans;
}
void add(int i, int val, int l, int r, int rt){
if(l==r){
sum[rt] = val;
return ;
}
int m = (l+r)>>1;
if(i<=m) add(i,val,lson);
else add(i,val,rson);
sum[rt] = sum[rt<<1] + sum[rt<<1|1];
}
int main(){
freopen("input.txt","r",stdin);
ios::sync_with_stdio(false);
int t;
cin >> t;
while(t--){
int n;
cin >> n;
build(1,n,1);
string str;
int a, b;
while(cin >> str){
if(str[0] == 'E') break;
cin >> a >> b;
if(str[0] == 'Q') cout << query(a,b,1,n,1) << endl;
if(str[0] == 'A') add(a,b,1,n,1);
else add(a,-b,1,n,1);
}
}
return 0;
}