#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 |
1 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
3 ms |
568 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 |
484 KB |
Output is correct |
8 |
Correct |
3 ms |
592 KB |
Output is correct |
9 |
Correct |
3 ms |
592 KB |
Output is correct |
10 |
Correct |
3 ms |
592 KB |
Output is correct |
11 |
Correct |
3 ms |
592 KB |
Output is correct |
12 |
Correct |
3 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
5192 KB |
Output is correct |
2 |
Correct |
32 ms |
4680 KB |
Output is correct |
3 |
Correct |
28 ms |
4952 KB |
Output is correct |
4 |
Correct |
36 ms |
5448 KB |
Output is correct |
5 |
Correct |
41 ms |
5976 KB |
Output is correct |
6 |
Correct |
41 ms |
5956 KB |
Output is correct |
7 |
Correct |
42 ms |
5960 KB |
Output is correct |
8 |
Correct |
49 ms |
5848 KB |
Output is correct |
9 |
Correct |
39 ms |
5732 KB |
Output is correct |
10 |
Correct |
48 ms |
5704 KB |
Output is correct |
11 |
Correct |
38 ms |
5688 KB |
Output is correct |
12 |
Correct |
38 ms |
5760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
1124 KB |
Output is correct |
2 |
Correct |
9 ms |
3152 KB |
Output is correct |
3 |
Correct |
11 ms |
3152 KB |
Output is correct |
4 |
Correct |
34 ms |
3960 KB |
Output is correct |
5 |
Correct |
41 ms |
4484 KB |
Output is correct |
6 |
Correct |
50 ms |
4424 KB |
Output is correct |
7 |
Correct |
36 ms |
4424 KB |
Output is correct |
8 |
Correct |
41 ms |
4436 KB |
Output is correct |
9 |
Correct |
38 ms |
4168 KB |
Output is correct |
10 |
Correct |
38 ms |
4168 KB |
Output is correct |
11 |
Correct |
43 ms |
4192 KB |
Output is correct |
12 |
Correct |
38 ms |
4168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
4432 KB |
Output is correct |
2 |
Correct |
55 ms |
4680 KB |
Output is correct |
3 |
Correct |
58 ms |
4168 KB |
Output is correct |
4 |
Correct |
68 ms |
4548 KB |
Output is correct |
5 |
Correct |
76 ms |
5652 KB |
Output is correct |
6 |
Correct |
85 ms |
5704 KB |
Output is correct |
7 |
Correct |
77 ms |
5716 KB |
Output is correct |
8 |
Correct |
107 ms |
5584 KB |
Output is correct |
9 |
Correct |
97 ms |
5512 KB |
Output is correct |
10 |
Correct |
104 ms |
5704 KB |
Output is correct |
11 |
Correct |
85 ms |
5560 KB |
Output is correct |
12 |
Correct |
138 ms |
5704 KB |
Output is correct |