This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 5;
struct node {
ll sum, mx;
node() {}
node(ll sum, ll mx) : sum(sum), mx(mx) {}
};
node operator + (node &a, node &b) {
node res;
res.sum = a.sum + b.sum;
res.mx = max(a.mx, b.mx);
return res;
}
int n, q, k;
node st[N << 2];
void update_point(int u, int val) {
int id = 1, l = 1, r = n;
while(l < r) {
int m = l + r >> 1;
if(u > m) id = id << 1 | 1, l = m + 1;
else id = id << 1, r = m;
}
st[id] = node(val, val);
while(id > 1) id = id >> 1, st[id] = st[id << 1] + st[id << 1 | 1];
}
void update(int u, int v, int id = 1, int l = 1, int r = n) {
if(u > r || v < l || st[id].mx == 0) return;
if(l == r) {
st[id].sum /= k;
st[id].mx /= k;
return;
}
int m = l + r >> 1;
update(u, v, id << 1, l, m);
update(u, v, id << 1 | 1, m + 1, r);
st[id] = st[id << 1] + st[id << 1 | 1];
}
ll query(int u, int v, int id = 1, int l = 1, int r = n) {
if(u > r || v < l) return 0;
if(u <= l && r <= v) return st[id].sum;
int m = l + r >> 1;
return query(u, v, id << 1, l, m) + query(u, v, id << 1 | 1, m + 1, r);
}
void solve() {
cin >> n >> q >> k;
for(int i = 1, x; i <= n; ++i) {
cin >> x;
update_point(i, x);
}
while(q--) {
int type, u, v; cin >> type >> u >> v;
if(type == 1) update_point(u, v);
if(type == 2) update(u, v);
if(type == 3) cout << query(u, v) << '\n';
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int test = 1;
// cin >> test;
while(test--) solve();
return 0;
}
Compilation message (stderr)
sterilizing.cpp: In function 'void update_point(int, int)':
sterilizing.cpp:25:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
25 | int m = l + r >> 1;
| ~~^~~
sterilizing.cpp: In function 'void update(int, int, int, int, int)':
sterilizing.cpp:40:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
40 | int m = l + r >> 1;
| ~~^~~
sterilizing.cpp: In function 'long long int query(int, int, int, int, int)':
sterilizing.cpp:49:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
49 | int m = l + r >> 1;
| ~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |