#include <bits/stdc++.h>
#define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
using namespace std;
const int N = 1e5 + 5;
int n, K, q;
struct node {
long long sum;
int mx;
node() {
sum = 0;
mx = 0;
}
node operator + (const node& o) const {
node res;
res.sum = sum + o.sum;
res.mx = max(mx, o.mx);
return res;
}
} it[N << 2];
void update(int k, int l, int r, int pos, int val) {
// cerr << l << ' ' << r << ' ' << pos << '\n';
if(l == r) {
it[k].sum = val;
it[k].mx = val;
return;
}
int mid = l + r >> 1;
if(pos <= mid) update(k << 1, l, mid, pos, val);
else update(k << 1 | 1, mid + 1, r, pos, val);
it[k] = it[k << 1] + it[k << 1 | 1];
}
void ope(int k, int l, int r, int u, int v) {
if(l > v || r < u) return;
if(l == r) {
it[k].sum /= K;
it[k].mx = it[k].sum;
return;
}
int mid = l + r >> 1;
if(it[k << 1].mx > 0) ope(k << 1, l, mid, u, v);
if(it[k << 1 | 1].mx > 0) ope(k << 1 | 1, mid + 1, r, u, v);
it[k] = it[k << 1] + it[k << 1 | 1];
}
long long get(int k, int l, int r, int u, int v) {
if(l > v || r < u) return 0;
if(u <= l && r <= v) return it[k].sum;
int mid = l + r >> 1;
return get(k << 1, l, mid, u, v) + get(k << 1 | 1, mid + 1, r, u, v);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
file("A") else file("task");
cin >> n >> q >> K;
// update(1, 1, n, 1, 1);
for(int i = 1; i <= n; ++i) {
int x;
cin >> x;
update(1, 1, n, i, x);
}
for(int _ = 1; _ <= q; ++_) {
int t, l, r;
cin >> t >> l >> r;
if(t == 1) {
update(1, 1, n, l, r);
} else if(t == 2) {
if(K > 1) ope(1, 1, n, l, r);
} else cout << get(1, 1, n, l, r) << '\n';
}
return 0;
}
Compilation message (stderr)
sterilizing.cpp: In function 'int main()':
sterilizing.cpp:2:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
2 | #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:56:5: note: in expansion of macro 'file'
56 | file("A") else file("task");
| ^~~~
sterilizing.cpp:2:91: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
2 | #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:56:5: note: in expansion of macro 'file'
56 | file("A") else file("task");
| ^~~~
sterilizing.cpp:2:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
2 | #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:56:20: note: in expansion of macro 'file'
56 | file("A") else file("task");
| ^~~~
sterilizing.cpp:2:91: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
2 | #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:56:20: note: in expansion of macro 'file'
56 | file("A") else file("task");
| ^~~~
# | 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... |