#include <iostream>
#define int long long
using namespace std;
const int MAX_N = 1e5;
int a[MAX_N + 1];
int aint[4 * MAX_N + 1];
int n, q, k;
void build(int v, int l, int r) {
if (l == r) {
aint[v] = a[l];
} else {
int mid = (l + r) / 2;
build(2 * v, l, mid);
build(2 * v + 1, mid + 1, r);
aint[v] = aint[2 * v] + aint[2 * v + 1];
}
}
void update(int v, int l, int r, int pos, int val) {
if (l == r) {
aint[v] = val;
} else {
int mid = (l + r) / 2;
if (pos <= mid) {
update(2 * v, l, mid, pos, val);
} else {
update(2 * v + 1, mid + 1, r, pos, val);
}
aint[v] = aint[2 * v] + aint[2 * v + 1];
}
}
void spray(int v, int l, int r, int p, int q) {
if (p > q || !aint[v]) {
return;
}
if (l == r) {
aint[v] /= k;
} else {
int mid = (l + r) / 2;
spray(2 * v, l, mid, p, min(mid, q));
spray(2 * v + 1, mid + 1, r, max(p, mid + 1), q);
aint[v] = aint[2 * v] + aint[2 * v + 1];
}
}
int query(int v, int l, int r, int p, int q) {
if (p > q) {
return 0;
} else if (l == p && r == q) {
return aint[v];
} else {
int mid = (l + r) / 2;
return query(2 * v, l, mid, p, min(mid, q)) + query(2 * v + 1, mid + 1, r, max(p, mid + 1), q);
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> q >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
build(1, 1, n);
for (int j = 1; j <= q; j++) {
int t, l, r;
cin >> t >> l >> r;
if (t == 1) {
update(1, 1, n, l, r);
} else if (t == 2 && k > 1) {
spray(1, 1, n, l, r);
} else {
cout << query(1, 1, n, l, r) << "\n";
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
51 ms |
2596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
524 KB |
Output is correct |
2 |
Correct |
12 ms |
1668 KB |
Output is correct |
3 |
Correct |
14 ms |
1724 KB |
Output is correct |
4 |
Correct |
38 ms |
1068 KB |
Output is correct |
5 |
Correct |
57 ms |
3192 KB |
Output is correct |
6 |
Correct |
50 ms |
3164 KB |
Output is correct |
7 |
Incorrect |
61 ms |
3796 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
1916 KB |
Output is correct |
2 |
Correct |
78 ms |
1964 KB |
Output is correct |
3 |
Correct |
85 ms |
1748 KB |
Output is correct |
4 |
Correct |
96 ms |
1332 KB |
Output is correct |
5 |
Correct |
110 ms |
3344 KB |
Output is correct |
6 |
Correct |
124 ms |
3412 KB |
Output is correct |
7 |
Correct |
127 ms |
3324 KB |
Output is correct |
8 |
Correct |
150 ms |
3424 KB |
Output is correct |
9 |
Correct |
153 ms |
3452 KB |
Output is correct |
10 |
Correct |
152 ms |
3400 KB |
Output is correct |
11 |
Correct |
118 ms |
3448 KB |
Output is correct |
12 |
Correct |
204 ms |
3440 KB |
Output is correct |