Submission #118959

#TimeUsernameProblemLanguageResultExecution timeMemory
118959IOrtroiiiSterilizing Spray (JOI15_sterilizing)C++14
100 / 100
286 ms5892 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 100100; int n, q, k; int a[N]; ll T[N << 2]; #define mid ((l + r) >> 1) void build(int v, int l, int r) { if (l == r) { T[v] = (ll) a[l]; return; } build(v << 1, l, mid); build(v << 1 | 1, mid + 1, r); T[v] = T[v << 1] + T[v << 1 | 1]; } void mdf(int v, int l, int r, int pos, int val) { if (l == r) { T[v] = (ll) val; return; } if (pos <= mid) mdf(v << 1, l, mid, pos, val); else mdf(v << 1 | 1, mid + 1, r, pos, val); T[v] = T[v << 1] + T[v << 1 | 1]; } void div(int v, int l, int r, int L, int R) { if (T[v] == 0 || k == 1) return; if (l == r) { T[v] /= k; return; } if (L <= mid) div(v << 1, l, mid, L, R); if (mid < R) div(v << 1 | 1, mid + 1, r, L, R); T[v] = T[v << 1] + T[v << 1 | 1]; } ll get(int v, int l, int r, int L, int R) { if (L <= l && r <= R) return T[v]; ll ans = 0; if (L <= mid) ans += get(v << 1, l, mid, L, R); if (mid < R) ans += get(v << 1 | 1, mid + 1, r, L, R); return ans; } int main() { ios_base::sync_with_stdio(false); cin >> n >> q >> k; for (int i = 1; i <= n; ++i) { cin >> a[i]; } build(1, 1, n); while (q--) { int op; cin >> op; if (op == 1) { int pos, val; cin >> pos >> val; mdf(1, 1, n, pos, val); } else if (op == 2) { int l, r; cin >> l >> r; div(1, 1, n, l, r); } else { int l, r; cin >> l >> r; cout << get(1, 1, n, l, r) << "\n"; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...