#include <bits/stdc++.h>
using namespace std;
#define int int64_t
const int N = 1e5+1;
int n, q, k;
int it[4*N], a[N];
void build(int id, int l, int r) {
if(l == r) {
it[id] = a[l];
return;
}
int m = (l+r)/2;
build(id*2, l, m);
build(id*2+1, m+1, r);
it[id] = it[id*2] + it[id*2+1];
}
void update(int id, int l, int r, int p, int val) {
if(l > p || r < p) return;
if(l == r) {
it[id] = val;
return;
}
int m = (l+r)/2;
update(id*2, l, m, p, val);
update(id*2+1, m+1, r, p, val);
it[id] = it[id*2] + it[id*2+1];
}
void dec(int id, int l, int r, int x, int y) {
if(it[id] == 0 || k == 1) return;
if(l > y || r < x) return;
if(l == r) {
it[id] /= k;
return;
}
int m = (l+r)/2;
dec(id*2, l, m, x, y);
dec(id*2+1, m+1, r, x, y);
it[id] = it[id*2] + it[id*2+1];
}
int get(int id, int l, int r, int x, int y) {
if(l > y || r < x) return 0;
if(l >= x && r <= y) return it[id];
int m = (l+r)/2;
return get(id*2, l, m, x, y) + get(id*2+1, m+1, r, x, y);
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> q >> k;
for(int i = 1; i <= n; i++) cin >> a[i];
build(1, 1, n);
while(q--) {
int t;
cin >> t;
if(t == 1) {
int p, val;
cin >> p >> val;
update(1, 1, n, p, val);
}
if(t == 2) {
int l, r;
cin >> l >> r;
dec(1, 1, n, l, r);
}
if(t == 3) {
int l, r;
cin >> l >> r;
cout << get(1, 1, n, l, r) << "\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
6 ms |
376 KB |
Output is correct |
5 |
Correct |
6 ms |
552 KB |
Output is correct |
6 |
Correct |
5 ms |
504 KB |
Output is correct |
7 |
Correct |
6 ms |
504 KB |
Output is correct |
8 |
Correct |
6 ms |
552 KB |
Output is correct |
9 |
Correct |
7 ms |
504 KB |
Output is correct |
10 |
Correct |
6 ms |
504 KB |
Output is correct |
11 |
Correct |
6 ms |
552 KB |
Output is correct |
12 |
Correct |
6 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
4088 KB |
Output is correct |
2 |
Correct |
56 ms |
3700 KB |
Output is correct |
3 |
Correct |
53 ms |
4988 KB |
Output is correct |
4 |
Correct |
66 ms |
5724 KB |
Output is correct |
5 |
Correct |
78 ms |
6136 KB |
Output is correct |
6 |
Correct |
75 ms |
6136 KB |
Output is correct |
7 |
Correct |
77 ms |
6136 KB |
Output is correct |
8 |
Correct |
80 ms |
6108 KB |
Output is correct |
9 |
Correct |
73 ms |
6008 KB |
Output is correct |
10 |
Correct |
72 ms |
6024 KB |
Output is correct |
11 |
Correct |
72 ms |
6008 KB |
Output is correct |
12 |
Correct |
72 ms |
6008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
1016 KB |
Output is correct |
2 |
Correct |
16 ms |
2040 KB |
Output is correct |
3 |
Correct |
21 ms |
2168 KB |
Output is correct |
4 |
Correct |
57 ms |
2268 KB |
Output is correct |
5 |
Correct |
73 ms |
4616 KB |
Output is correct |
6 |
Correct |
75 ms |
4672 KB |
Output is correct |
7 |
Correct |
65 ms |
4732 KB |
Output is correct |
8 |
Correct |
74 ms |
4600 KB |
Output is correct |
9 |
Correct |
67 ms |
4472 KB |
Output is correct |
10 |
Correct |
67 ms |
4604 KB |
Output is correct |
11 |
Correct |
74 ms |
4664 KB |
Output is correct |
12 |
Correct |
70 ms |
4556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
3580 KB |
Output is correct |
2 |
Correct |
102 ms |
3704 KB |
Output is correct |
3 |
Correct |
122 ms |
3072 KB |
Output is correct |
4 |
Correct |
127 ms |
3008 KB |
Output is correct |
5 |
Correct |
151 ms |
5880 KB |
Output is correct |
6 |
Correct |
172 ms |
5936 KB |
Output is correct |
7 |
Correct |
151 ms |
5880 KB |
Output is correct |
8 |
Correct |
214 ms |
5880 KB |
Output is correct |
9 |
Correct |
177 ms |
6000 KB |
Output is correct |
10 |
Correct |
200 ms |
5808 KB |
Output is correct |
11 |
Correct |
153 ms |
5752 KB |
Output is correct |
12 |
Correct |
264 ms |
5764 KB |
Output is correct |