-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathneps43.cpp
More file actions
57 lines (44 loc) · 856 Bytes
/
Copy pathneps43.cpp
File metadata and controls
57 lines (44 loc) · 856 Bytes
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
/*
* Contest : OBI 2017 - Fase 3
* Problem : Arranha-céu
* Link : https://neps.academy/br/exercise/43
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
const int MAXN = 1e5 + 1;
int bit[MAXN], n, q;
// soma v em V[i]
void upd(int i, int v) {
// lsb(i) = i&-i
for (; i <= n; i += (i & -i)) bit[i] += v;
}
// soma de [1, i]
int sum(int i) {
int ans = 0;
for (; i > 0; i -= (i & -i)) ans += bit[i];
return ans;
}
int main() {
fastio
cin >> n >> q;
vector<int> vet(n + 1, 0);
for (int i = 1; i <= n; i++) {
cin >> vet[i];
upd(i, vet[i]);
}
while (q--) {
int op, k, p;
cin >> op >> k;
if (op) {
cout << sum(k) << "\n";
}
else {
cin >> p;
upd(k, p - vet[k]);
vet[k] = p;
}
}
return 0;
}