#include <bits/stdc++.h>
#define int long long
using namespace std;
const int NS = (int)1e5 + 4;
int n, q, k;
int a[NS];
int fenw[NS];
void add(int x, int val){for(int i = x; i < NS; i += (i & -i)){fenw[i] += val;}}
int get(int x){int rv = 0; for(int i = x; i > 0; i -= (i & -i)){rv += fenw[i];} return rv;}
int tr[NS * 4];
void push(int x, int s, int e, int pos, int val){
if(s == e){
tr[x] = val;
return;
}
int m = s + e >> 1;
if(pos <= m){
push(x * 2, s, m, pos, val);
}
else{
push(x * 2 + 1, m + 1, e, pos, val);
}
tr[x] = tr[x * 2] + tr[x * 2 + 1];
}
int get(int x, int s, int e, int fs, int fe){
if(fe < s || fs > e || !tr[x]) return (int)1e9;
if(s == e){
return s;
}
int m = s + e >> 1;
int rv = get(x * 2, s, m, fs, fe);
if(rv != (int)1e9) return rv;
return get(x * 2 + 1, m + 1, e, fs, fe);
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> q >> k;
for(int i = 1; i <= n; ++i){
cin >> a[i];
add(i, a[i]);
if(a[i] && k > 1){
push(1, 1, n, i, 1);
}
}
while(q--){
int x, y, z; cin >> x >> y >> z;
if(x == 1){
add(y, -a[y]);
a[y] = z;
add(y, a[y]);
if(a[y] && k > 1){
push(1, 1, n, y, 1);
}
else{
push(1, 1, n, y, 0);
}
}
else if(x == 2){
int pos = get(1, 1, n, y, z);
while(pos <= z){
add(pos, -a[pos]);
a[pos] /= k;
add(pos, a[pos]);
if(a[pos] && k > 1){
push(1, 1, n, pos, 1);
}
else{
push(1, 1, n, pos, 0);
}
pos = get(1, 1, n, pos + 1, z);
}
}
else{
cout << get(z) - get(y - 1) << '\n';
}
}
return 0;
}
Compilation message
sterilizing.cpp: In function 'void push(long long int, long long int, long long int, long long int, long long int)':
sterilizing.cpp:24:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
24 | int m = s + e >> 1;
| ~~^~~
sterilizing.cpp: In function 'long long int get(long long int, long long int, long long int, long long int, long long int)':
sterilizing.cpp:42:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
42 | int m = s + e >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
360 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
6 ms |
336 KB |
Output is correct |
4 |
Correct |
13 ms |
468 KB |
Output is correct |
5 |
Correct |
12 ms |
464 KB |
Output is correct |
6 |
Correct |
8 ms |
464 KB |
Output is correct |
7 |
Correct |
11 ms |
468 KB |
Output is correct |
8 |
Correct |
10 ms |
468 KB |
Output is correct |
9 |
Correct |
14 ms |
548 KB |
Output is correct |
10 |
Correct |
15 ms |
536 KB |
Output is correct |
11 |
Correct |
14 ms |
540 KB |
Output is correct |
12 |
Correct |
13 ms |
464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
3320 KB |
Output is correct |
2 |
Correct |
38 ms |
3028 KB |
Output is correct |
3 |
Correct |
47 ms |
4612 KB |
Output is correct |
4 |
Correct |
43 ms |
5068 KB |
Output is correct |
5 |
Correct |
51 ms |
5120 KB |
Output is correct |
6 |
Correct |
57 ms |
5068 KB |
Output is correct |
7 |
Correct |
72 ms |
5096 KB |
Output is correct |
8 |
Correct |
48 ms |
5060 KB |
Output is correct |
9 |
Correct |
51 ms |
5136 KB |
Output is correct |
10 |
Correct |
62 ms |
5156 KB |
Output is correct |
11 |
Correct |
68 ms |
5184 KB |
Output is correct |
12 |
Correct |
58 ms |
5168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
1000 KB |
Output is correct |
2 |
Correct |
24 ms |
2260 KB |
Output is correct |
3 |
Correct |
28 ms |
2436 KB |
Output is correct |
4 |
Correct |
43 ms |
2096 KB |
Output is correct |
5 |
Correct |
69 ms |
4876 KB |
Output is correct |
6 |
Correct |
65 ms |
4896 KB |
Output is correct |
7 |
Correct |
39 ms |
4960 KB |
Output is correct |
8 |
Correct |
88 ms |
4984 KB |
Output is correct |
9 |
Correct |
57 ms |
4876 KB |
Output is correct |
10 |
Correct |
56 ms |
4808 KB |
Output is correct |
11 |
Correct |
64 ms |
4848 KB |
Output is correct |
12 |
Correct |
79 ms |
4812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
206 ms |
2692 KB |
Output is correct |
2 |
Correct |
237 ms |
3244 KB |
Output is correct |
3 |
Correct |
420 ms |
2872 KB |
Output is correct |
4 |
Correct |
273 ms |
2524 KB |
Output is correct |
5 |
Correct |
374 ms |
5044 KB |
Output is correct |
6 |
Correct |
428 ms |
5052 KB |
Output is correct |
7 |
Correct |
326 ms |
5100 KB |
Output is correct |
8 |
Correct |
593 ms |
5096 KB |
Output is correct |
9 |
Correct |
476 ms |
5176 KB |
Output is correct |
10 |
Correct |
687 ms |
5148 KB |
Output is correct |
11 |
Correct |
402 ms |
5044 KB |
Output is correct |
12 |
Correct |
952 ms |
5136 KB |
Output is correct |