#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
#define int long long
#define fi first
#define se second
int k;
struct SegTree {
int size = 1;
vector<pair<int, int>> seg;
void init(int sz) {
while (size < sz) size *= 2;
seg.assign(2 * size + 1, {0, 0});
}
void pull(int id) {
seg[id].first = max(seg[id * 2].first, seg[id * 2 + 1].first);
seg[id].second = seg[id * 2].second + seg[id * 2 + 1].second;
}
void update(int pos, int val, int l, int r, int id) {
if (l == r) {
seg[id] = {val, val};
return;
}
int mid = (l + r) / 2;
if (pos <= mid) update(pos, val, l, mid, id * 2);
else update(pos, val, mid + 1, r, id * 2 + 1);
pull(id);
}
void spray(int ql, int qr, int l, int r, int id) {
if (seg[id].first == 0 || qr < l || r < ql) return;
if (l == r) {
seg[id].first /= k;
seg[id].second = seg[id].first;
return;
}
int mid = (l + r) / 2;
spray(ql, qr, l, mid, id * 2);
spray(ql, qr, mid + 1, r, id * 2 + 1);
pull(id);
}
int query(int ql, int qr, int l, int r, int id) {
if (qr < l || r < ql) return 0;
if (ql <= l && r <= qr) return seg[id].second;
int mid = (l + r) / 2;
return query(ql, qr, l, mid, id * 2) + query(ql, qr, mid + 1, r, id * 2 + 1);
}
} ST;
void solve() {
int n, q;
cin >> n >> q >> k;
vector<int> c(n+1);
ST.init(n + 1);
for (int i = 1; i <= n; i++) {
cin >> c[i];
ST.update(i, c[i], 1, n, 1);
}
for (int i = 1; i <= q; i++) {
int s, t, u;
cin >> s >> t >> u;
if (s == 1) {
ST.update(t, u, 1, n, 1);
} else if (s == 2) {
if (k != 1) ST.spray(t, u, 1, n, 1);
} else {
cout << ST.query(t, u, 1, n, 1) << '\n';
}
}
}
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0);
int test = 1;
// cin >> test;
while (test--) solve();
}
# | 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... |