#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct node{
ll sum;
};
const int MAXN = 1e5 + 10;
int a[MAXN];
node seg[4 * MAXN];
void build(int x, int lx, int rx){
if(lx == rx){
seg[x].sum = a[lx];
return;
}
int m = (lx + rx) / 2;
int lc = 2 * x, rc = 2 * x + 1;
build(lc, lx, m);
build(rc, m + 1, rx);
seg[x].sum = seg[lc].sum + seg[rc].sum;
}
void update_set(int x, int lx, int rx, int i, int val){
if(rx < i || lx > i) return;
if(lx == rx){
seg[x].sum = val;
return;
}
int m = (lx + rx) / 2;
int lc = 2 * x, rc = 2 * x + 1;
update_set(lc, lx, m, i, val);
update_set(rc, m + 1, rx, i, val);
seg[x].sum = seg[lc].sum + seg[rc].sum;
}
void update(int x, int lx, int rx, int l, int r, int k){
if(rx < l || lx > r || seg[x].sum == 0) return;
if(lx == rx){
seg[x].sum /= k;
return;
}
int m = (lx + rx) / 2;
int lc = 2 * x, rc = 2 * x + 1;
update(lc, lx, m, l, r, k);
update(rc, m + 1, rx, l, r, k);
seg[x].sum = seg[lc].sum + seg[rc].sum;
}
ll query(int x, int lx, int rx, int l, int r){
if(rx < l || lx > r) return 0;
if(l <= lx && rx <= r) return seg[x].sum;
int m = (lx + rx) / 2;
int lc = 2 * x, rc = 2 * x + 1;
return query(lc, lx, m, l, r) + query(rc, m + 1, rx, l, r);
}
int main(){
cin.tie(0)->sync_with_stdio(0);
int n, q, k; cin >> n >> q >> k;
for(int i=1; i<=n; i++){
cin >> a[i];
}
build(1, 1, n);
while(q--){
int t, a, b; cin >> t >> a >> b;
if(t == 1){
update_set(1, 1, n, a, b);
} else if(t == 2){
if(k != 1) update(1, 1, n, a, b, k);
} else{
cout << query(1, 1, n, a, b) << "\n";
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
3 ms |
336 KB |
Output is correct |
5 |
Correct |
3 ms |
592 KB |
Output is correct |
6 |
Correct |
3 ms |
592 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
4 ms |
592 KB |
Output is correct |
9 |
Correct |
4 ms |
592 KB |
Output is correct |
10 |
Correct |
3 ms |
592 KB |
Output is correct |
11 |
Correct |
3 ms |
548 KB |
Output is correct |
12 |
Correct |
3 ms |
548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
2120 KB |
Output is correct |
2 |
Correct |
33 ms |
3456 KB |
Output is correct |
3 |
Correct |
27 ms |
4728 KB |
Output is correct |
4 |
Correct |
34 ms |
5200 KB |
Output is correct |
5 |
Correct |
46 ms |
5736 KB |
Output is correct |
6 |
Correct |
50 ms |
5748 KB |
Output is correct |
7 |
Correct |
48 ms |
5700 KB |
Output is correct |
8 |
Correct |
60 ms |
5676 KB |
Output is correct |
9 |
Correct |
46 ms |
5528 KB |
Output is correct |
10 |
Correct |
56 ms |
5644 KB |
Output is correct |
11 |
Correct |
57 ms |
5624 KB |
Output is correct |
12 |
Correct |
40 ms |
5712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
592 KB |
Output is correct |
2 |
Correct |
12 ms |
1616 KB |
Output is correct |
3 |
Correct |
17 ms |
1696 KB |
Output is correct |
4 |
Correct |
30 ms |
1104 KB |
Output is correct |
5 |
Correct |
39 ms |
2896 KB |
Output is correct |
6 |
Correct |
39 ms |
2968 KB |
Output is correct |
7 |
Correct |
37 ms |
2996 KB |
Output is correct |
8 |
Correct |
41 ms |
3912 KB |
Output is correct |
9 |
Correct |
37 ms |
3656 KB |
Output is correct |
10 |
Correct |
36 ms |
2948 KB |
Output is correct |
11 |
Correct |
37 ms |
3672 KB |
Output is correct |
12 |
Correct |
36 ms |
2896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
1868 KB |
Output is correct |
2 |
Correct |
62 ms |
3384 KB |
Output is correct |
3 |
Correct |
59 ms |
2888 KB |
Output is correct |
4 |
Correct |
84 ms |
2888 KB |
Output is correct |
5 |
Correct |
97 ms |
5420 KB |
Output is correct |
6 |
Correct |
111 ms |
5576 KB |
Output is correct |
7 |
Correct |
89 ms |
5476 KB |
Output is correct |
8 |
Correct |
119 ms |
5616 KB |
Output is correct |
9 |
Correct |
103 ms |
5456 KB |
Output is correct |
10 |
Correct |
152 ms |
5520 KB |
Output is correct |
11 |
Correct |
94 ms |
5324 KB |
Output is correct |
12 |
Correct |
155 ms |
5320 KB |
Output is correct |