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 <bits/stdc++.h>
using namespace std;
struct SegmentTree {
vector<long long> T;
int n;
SegmentTree(const vector<int> &v) : n(v.size()) {
while (n & n - 1) ++n;
T.resize(n << 1);
for (int i = 0; i < v.size(); i++) {
T[i + n] = v[i];
}
for (int i = n - 1; i > 0; i--) {
T[i] = T[i << 1] + T[i << 1 | 1];
}
}
void upd0(int v, int l, int r, int u, int x) {
if (l == r) {
T[v] = x;
return;
}
int m = l + r >> 1;
if (u <= m) upd0(v << 1, l, m, u, x);
else upd0(v << 1 | 1, m + 1, r, u, x);
T[v] = T[v << 1] + T[v << 1 | 1];
}
void upd1(int v, int l, int r, int ql, int qr, const int &x) {
if (l > qr || r < ql || !T[v]) return;
if (l == r) {
T[v] /= x;
return;
}
int m = l + r >> 1;
upd1(v << 1, l, m, ql, qr, x);
upd1(v << 1 | 1, m + 1, r, ql, qr, x);
T[v] = T[v << 1] + T[v << 1 | 1];
}
long long qry(int v, int l, int r, int ql, int qr) {
if (l > qr || r < ql) return 0;
if (l >= ql && r <= qr) return T[v];
int m = l + r >> 1;
return qry(v << 1, l, m, ql, qr) + qry(v << 1 | 1, m + 1, r, ql, qr);
}
void upd0(int u, int x) {
upd0(1, 0, n - 1, u, x);
}
void upd1(int l, int r, const int &x) {
upd1(1, 0, n - 1, l, r, x);
}
long long qry(int l, int r) {
return qry(1, 0, n - 1, l, r);
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, q, k;
cin >> n >> q >> k;
vector<int> v(n);
for (int &x : v) {
cin >> x;
}
SegmentTree st(v);
while (q--) {
int s, t, u;
cin >> s >> t >> u;
if (s == 1) {
st.upd0(--t, u);
} else if (s == 2) {
if (k > 1) st.upd1(--t, --u, k);
} else {
cout << st.qry(--t, --u) << '\n';
}
}
return 0;
}
Compilation message (stderr)
sterilizing.cpp: In constructor 'SegmentTree::SegmentTree(const std::vector<int>&)':
sterilizing.cpp:9:22: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
9 | while (n & n - 1) ++n;
| ~~^~~
sterilizing.cpp:11:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | for (int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
sterilizing.cpp: In member function 'void SegmentTree::upd0(int, int, int, int, int)':
sterilizing.cpp:23:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
23 | int m = l + r >> 1;
| ~~^~~
sterilizing.cpp: In member function 'void SegmentTree::upd1(int, int, int, int, int, const int&)':
sterilizing.cpp:34:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
34 | int m = l + r >> 1;
| ~~^~~
sterilizing.cpp: In member function 'long long int SegmentTree::qry(int, int, int, int, int)':
sterilizing.cpp:42:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
42 | int m = l + r >> 1;
| ~~^~~
# | 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... |