#include "bits/stdc++.h"
using namespace std;
#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define int long long
const int mod = 1e9 + 7;
const int inf = 2e18;
const int N = 1e5 + 7;
int n, q, k, a[N];
struct segtree {
vector<int> st;
int n;
segtree() {}
segtree(int n) : n(n) {
st.resize(n * 4 + 1, 0);
}
void build(int i, int l, int r) {
if(l == r) {
st[i] = a[l];
return;
}
int m = (l + r) >> 1;
build(i * 2, l, m);
build(i * 2 + 1, m + 1, r);
st[i] = st[i * 2] + st[i * 2 + 1];
}
void update(int i, int l, int r, int u, int x) {
if(l == r) {
st[i] = x;
return;
}
int m = (l + r) >> 1;
if(u <= m) update(i * 2, l, m, u, x);
else update(i * 2 + 1, m + 1, r, u, x);
st[i] = st[i * 2] + st[i * 2 + 1];
}
int get(int i, int l, int r, int u, int v) {
if(u > r or v < l) return 0;
if(u <= l and r <= v) return st[i];
int m = (l + r) >> 1;
return get(i * 2, l, m, u, v) + get(i * 2 + 1, m + 1, r, u, v);
}
};
signed main() {
cin.tie(0) -> sync_with_stdio(0);
cin >> n >> q >> k;
set<int> s;
for(int i = 1; i <= n; i++) cin >> a[i], s.insert(i);
segtree st(n);
st.build(1, 1, n);
for(int i = 1; i <= q; i++) {
int t, l, r; cin >> t >> l >> r;
if(t == 1) {
st.update(1, 1, n, l, r);
if(a[l] > 0) s.erase(s.find(l));
a[l] = r;
if(a[l] > 0) s.insert(l);
} else if(t == 2) {
if(k == 1) continue;
auto it = s.lower_bound(l);
vector<int> vec;
while(*it <= r and it != s.end()) {
int x = *it;
a[x] /= k;
if(a[x] == 0) vec.pb(x);
st.update(1, 1, n, x, a[x]);
it++;
}
for(auto x : vec) s.erase(s.find(x));
} else {
cout << st.get(1, 1, n, l, r) << ln;
}
}
cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}
# | 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... |