-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcu3214.cpp
More file actions
60 lines (53 loc) · 1.14 KB
/
Copy pathcu3214.cpp
File metadata and controls
60 lines (53 loc) · 1.14 KB
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
#include <bits/stdc++.h>
using namespace std;
int n, m, x, me, a, b, cnt = 1;
int tree[400040];
void printTree(){
for(int i = 1; i < 2*cnt; i++){
printf("%d, ", tree[i]);
}
puts("");
}
void renewal(int t, int k){
tree[t] = k;
t = t/2;
while(t > 0){
//printf("%d, ",t);
tree[t] = tree[t*2] + tree[t*2+1];
t = t/2;
}
}
int f(int s, int e, int l, int r, int node){
//printf("(%d %d), ", l, r);
if(s <= l && r <= e){
return tree[node];
}
else if(r < s || l > e){
return 0;
}
else{
return f(s,e,l,(l+r)/2,node*2) + f(s,e,(l+r)/2+1, r, node*2+1);
}
}
int main (){
scanf("%d", &n);
while(cnt < n){
cnt *= 2;
}
for(int i = cnt; i < 2*cnt; i++){
tree[i] = 0;
}
for(int i = 0; i < n; i++){
scanf("%d", tree+cnt+i);
}
for(int i = cnt-1; i > 0; i--){
tree[i] = tree[i*2] + tree[i*2+1];
}
scanf("%d %d", &m, &me);
m += me;
while(m--){
scanf("%d %d %d", &x, &a, &b);
if(x == 0) renewal(cnt+a-1,b);
else printf("%d\n",f(a,b,1,cnt,1));
}
}