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 <iostream>
using namespace std;
long long n, test, k, a[100010], node[400010];
void build(int id, int x, int y) {
if (x == y) {
node[id] = a[x];
return;
}
int mid = (x+y)/2;
build(id*2,x,mid);
build(id*2+1,mid+1,y);
node[id] = node[id*2]+node[id*2+1];
}
void update(int id, int x, int y, int pos, int val) {
if (x == y) {
node[id] = val;
return;
}
int mid = (x+y)/2;
if (pos <= mid) update(id*2,x,mid,pos,val);
else update(id*2+1,mid+1,y,pos,val);
node[id] = node[id*2]+node[id*2+1];
}
void spray(int id, int x, int y, int l, int r) {
if (node[id] == 0) return;
if ((y < l) || (r < x)) return;
if (x == y) {
node[id] /= k;
return;
}
int mid = (x+y)/2;
spray(id*2,x,mid,l,r);
spray(id*2+1,mid+1,y,l,r);
node[id] = node[id*2]+node[id*2+1];
}
long long sum(int id, int x, int y, int l, int r) {
if ((l <= x) && (y <= r)) return node[id];
if ((y < l) || (r < x)) return 0;
int mid = (x+y)/2;
return sum(id*2,x,mid,l,r)+sum(id*2+1,mid+1,y,l,r);
}
int main() {
cin >> n >> test >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
build(1,1,n);
while (test--) {
int type, l, r;
cin >> type >> l >> r;
if (type == 1) update(1,1,n,l,r);
if ((type == 2) && (k > 1)) spray(1,1,n,l,r);
if (type == 3) cout << sum(1,1,n,l,r) << "\n";
}
}
# | 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... |