-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCuriousRobinHood.cpp
More file actions
89 lines (75 loc) · 1.66 KB
/
Copy pathCuriousRobinHood.cpp
File metadata and controls
89 lines (75 loc) · 1.66 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <bits/stdc++.h>
#define _ \
ios_base::sync_with_stdio(0); \
cin.tie(0);
#define endl '\n'
#define pb push_back
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
struct BIT {
int n;
vector<ll> t;
BIT(int n) : n(n) { t.assign(n + 1, 0); }
BIT(vector<ll> const &a) {
n = a.size();
t.assign(n + 1, 0);
for (int i = 1; i <= n; ++i) {
t[i] += a[i - 1];
int j = i + (i & -i);
if (j <= n)
t[j] += t[i];
}
}
ll query(int i) {
ll ret = 0;
for (++i; i > 0; i -= i & -i)
ret += t[i];
return ret;
}
void update(int i, ll add) {
for (++i; i <= n; i += i & -i)
t[i] += add;
}
void update(int l, int r, ll add) {
update(l, add);
update(r + 1, -add);
}
};
int main() {
_ int T;
cin >> T;
for (int tc = 1; tc <= T; tc++) {
int n, q;
cin >> n >> q;
vector<ll> A(n);
for (int i = 0; i < n; i++)
cin >> A[i];
BIT bit(A);
cout << "Case " << tc << ":" << endl;
while (q--) {
int op;
cin >> op;
if (op == 1) {
int i;
cin >> i;
cout << A[i] << endl;
bit.update(i, -A[i]);
A[i] = 0;
} else if (op == 2) {
int i;
ll v;
cin >> i >> v;
bit.update(i, v);
A[i] += v;
} else {
int i, j;
cin >> i >> j;
cout << bit.query(j) - (i > 0 ? bit.query(i - 1) : 0) << endl;
}
}
}
}