-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2268.cpp
48 lines (39 loc) · 942 Bytes
/
2268.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
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll MAX = 1e6+1;
ll tree[MAX*4];
ll arr[MAX];
void update(int s, int e, int node, int index, ll diff) {
if (index < s || index > e) return;
tree[node] += diff;
if (s == e) return;
int m=(s+e)/2;
update(s, m, node*2, index, diff);
update(m+1, e, node*2+1, index, diff);
}
ll query(int s, int e, int node, int from, int to) {
if (s > to || e < from) return 0;
if (s >= from && to >= e) return tree[node];
int m = (s+e)/2;
return query(s, m, node*2, from, to) + query(m+1, e, node*2+1, from, to);
}
void solve() {
int N, M; cin >> N>>M;
for (int i = 0; i < M; i++) {
ll a,b,c;cin>>a>>b>>c;
if (a==1) {
update(1,N,1,b,c-arr[b]);
arr[b]=c;
} else {
cout << query(1,N,1,min(b,c),max(b,c)) << '\n';
}
}
}
int main(){
cin.tie(0)->sync_with_stdio(0);
cout.tie(0);
solve();
return 0;
}