# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
571252 | 2022-06-01T15:25:53 Z | Tien_Noob | Sterilizing Spray (JOI15_sterilizing) | C++17 | 0 ms | 0 KB |
//Make CSP great again //Vengeance #include <bits/stdc++.h> #define TASK "TESTCODE" #define Log2(x) 31 - __builtin_clz(x) using namespace std; const int N = 1e5; int n, q, a[N + 1], k; set<int> num; struct FenwickTree { long long tree[N + 1]; void add(int pos, int val) { for (; pos <= n; pos += (pos & (-pos))) { tree[pos] += val; } } long long sum(int pos) { long long ret = 0; for (; pos > 0; pos -= (pos & (-pos))) { ret += tree[pos]; } return ret; } long long sum(int l, int r) { return sum(r) - sum(l - 1); } } tree; void read() { cin >> n >> q >> k; for (int i = 1; i <= n; ++ i) { cin >> a[i]; if (a[i]) { num.insert(i); tree.add(i, a[i]); } } } void solve() { while(q--) { int t; cin >> t; if (t == 1) { int i, x; cin >> i >> x; tree.add(i, -a[i]); a[i] = x; tree.add(i, a[i]); if (a[i]) { num.insert(i); } } else if (t == 2) { int l, r; cin >> l >> r; if (k == 1) { continue; } vector<int> valid; while(true) { auto it = num.lower_bound(l); if (it == num.end() || *it > r) { for (int i : valid) { num.insert(i); } break; } tree.add(*it, -a[*it]); a[*it] /= k; if (a[*it]) { tree.add(*it, a[*it]); valid.push_back(*it); } num.erase(it); } } else { int l, r; cin >> l >> r; cout << tree.sum(l, r) << '\n'; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen(TASK".INP", "r")) { freopen(TASK".INP", "r", stdin) //freopen(TASK".OUT", "w", stdout); } int t = 1; bool typetest = false; if (typetest) { cin >> t; } for (int __ = 1; __ <= t; ++ __) { //cout << "Case #" << __ << ":" << '\n'; read(); solve(); } }