Submission #776372

#TimeUsernameProblemLanguageResultExecution timeMemory
776372Hacv16Sterilizing Spray (JOI15_sterilizing)C++17
80 / 100
5053 ms3740 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") typedef long long ll; const int MAX = 1e5 + 15; ll n, q, k, v[MAX], seg[4 * MAX]; void build(int p, int l, int r){ if(l == r){ seg[p] = v[l]; return; } int m = (l + r) >> 1, e = 2 * p, d = e + 1; build(e, l, m); build(d, m + 1, r); seg[p] = seg[e] + seg[d]; } ll query(int a, int b, int p, int l, int r){ if(a > r || b < l) return 0; if(a <= l && r <= b) return seg[p]; int m = (l + r) >> 1, e = 2 * p, d = e + 1; return query(a, b, e, l, m) + query(a, b, d, m + 1, r); } void update(int i, ll x, int p, int l, int r){ if(i > r || i < l) return; if(l == r){ seg[p] = x; return; } int m = (l + r) >> 1, e = 2 * p, d = e + 1; update(i, x, e, l, m); update(i, x, d, m + 1, r); seg[p] = seg[e] + seg[d]; } void spray(int a, int b, int p, int l, int r){ if(seg[p] == 0 || a > r || b < l) return; if(l == r){ seg[p] /= k; return; } int m = (l + r) >> 1, e = 2 * p, d = e + 1; spray(a, b, e, l, m); spray(a, b, d, m + 1, r); seg[p] = seg[e] + seg[d]; } int32_t main(void){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> q >> k; for(int i = 1; i <= n; i++) cin >> v[i]; build(1, 1, n); while(q--){ int op; cin >> op; if(op == 1){ ll i, x; cin >> i >> x; update(i, x, 1, 1, n); }else if(op == 2){ ll l, r; cin >> l >> r; spray(l, r, 1, 1, n); }else{ ll l, r; cin >> l >> r; cout << query(l, r, 1, 1, n) << '\n'; } } exit(0); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...