#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define F first
#define S second
#define pb push_back
#define pii pair<int,int>
const int N = 2e5 + 5;
int n, q;
int k, c[N];
int st[4 * N];
int st_mx[4 * N];
void build(int id, int l, int r) {
if (l == r) {
st[id] = st_mx[id] = c[l];
return;
}
int mid = (l + r) / 2;
build(id * 2, l, mid);
build(id * 2 + 1, mid + 1, r);
st[id] = st[id * 2] + st[id * 2 + 1];
st_mx[id] = max(st_mx[id * 2], st_mx[id * 2 + 1]);
}
void update1(int id, int l, int r, int i, int x) {
if (l == r) {
st[id] = st_mx[id] = x;
return;
}
int mid = (l + r) / 2;
if (mid < i) update1(id * 2 + 1, mid + 1, r, i, x);
else update1(id * 2, l, mid, i, x);
st[id] = st[id * 2] + st[id * 2 + 1];
st_mx[id] = max(st_mx[id * 2], st_mx[id * 2 + 1]);
}
void update2(int id, int l, int r, int u, int v) {
if (v < l || u > r || st_mx[id] == 0) {
return;
}
if (l == r) {
st[id] /= k;
st_mx[id] /= k;
return;
}
int mid = (l + r) / 2;
update2(id * 2, l, mid, u, v);
update2(id * 2 + 1, mid + 1, r, u, v);
st[id] = st[id * 2] + st[id * 2 + 1];
st_mx[id] = max(st_mx[id * 2], st_mx[id * 2 + 1]);
}
int get(int id, int l, int r, int u, int v) {
if (u <= l && r <= v) {
return st[id];
}
int mid = (l + r) / 2;
if (u > mid) return get(id * 2 + 1, mid + 1, r, u, v);
if (v <= mid) return get(id * 2, l, mid, u, v);
return get(id * 2, l, mid, u, v) + get(id * 2 + 1, mid + 1, r, u, v);
}
signed main(){
ios_base::sync_with_stdio(false) ;
cin.tie(0) ; cout.tie(0) ;
if (fopen("INP.INP" ,"r")) {
freopen("INP.INP" ,"r" , stdin) ;
freopen("OUT.OUT" , "w" , stdout) ;
}
cin >> n >> q >> k;
for (int i = 1; i <= n; i++) {
cin >> c[i];
}
build(1, 1, n);
for (int i = 1; i <= q; i++) {
int type, x, y;
cin >> type >> x >> y;
if (type == 1) {
update1(1, 1, n, x, y);
}
if (type == 2) {
if (k != 1) update2(1, 1, n, x, y);
}
if (type == 3) {
cout << get(1, 1, n, x, y) << '\n';
}
}
}
Compilation message (stderr)
sterilizing.cpp: In function 'int main()':
sterilizing.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
72 | freopen("INP.INP" ,"r" , stdin) ;
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
73 | freopen("OUT.OUT" , "w" , stdout) ;
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |