-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2042.cpp
More file actions
59 lines (45 loc) · 1.02 KB
/
2042.cpp
File metadata and controls
59 lines (45 loc) · 1.02 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 <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
using ll = long long;
const int ST_size = 1<<20;
ll N,M,K,ST[ST_size*2];
void build(){
for(int i=ST_size-1 ; i>=1 ; i--){
ST[i] = ST[i*2] + ST[i*2+1];
}
}
void update(ll idx, ll num){
int n = ST_size+idx;
ST[n] = num;
for(int i=n/2 ; i>0 ; i/=2){
ST[i] = ST[i*2] + ST[i*2+1];
}
}
ll getSum(int n, int nl, int nr, int l, int r){
if(l>nr || r<nl) return 0;
if(l<=nl && nr<=r) return ST[n];
int mid = (nl+nr)/2;
return getSum(n*2,nl,mid,l,r) + getSum(n*2+1,mid+1,nr,l,r);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin >> N >> M >> K;
for(int i=1 ; i<=N ; i++){
ll x; cin >> x;
ST[ST_size+i] = x;
}
build();
for(int i=0 ; i<M+K ; i++){
ll a,b,c;
cin >> a >> b >> c;
if(a==1){
update(b,c);
}else {
cout << getSum(1,0,ST_size-1,b,c) << '\n';
}
}
}