# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
153112 | karma | Sterilizing Spray (JOI15_sterilizing) | C++14 | 242 ms | 9184 KiB |
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>
#pragma GCC optimize("O3")
#define ll long long
#define pb emplace_back
using namespace std;
const int N = int(1e5) + 2;
int n, q, k, a[N], irene, cmd, x, y;
ll t[N];
set<int> s;
vector<int> rmv;
void Update(int x, int val) {
for(; x <= n; x += (x & -x)) t[x] += val;
}
ll Query(int x) {
ll res = 0;
for(; x > 0; x -= (x & -x)) res += t[x];
return res;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
if(fopen("test.inp", "r")) {
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
cin >> n >> q >> k;
for(int i = 1; i <= n; ++i) {
cin >> a[i]; Update(i, a[i]);
if(a[i]) s.insert(i);
}
rmv.clear();
while(q --) {
cin >> cmd >> x >> y;
if(cmd == 1) {
if(y && !a[x]) s.insert(x);
Update(x, y - a[x]); a[x] = y;
} else if(cmd == 2) {
if(k == 1) continue;
auto ptr = s.lower_bound(x);
while(*ptr >= x && *ptr <= y && ptr != s.end()) {
irene = a[*ptr] / k;
Update(*ptr, irene - a[*ptr]);
if(!irene) rmv.pb(*ptr);
a[*ptr] = irene, ptr = next(ptr);
}
while(rmv.size()) s.erase(rmv.back()), rmv.pop_back();
} else cout << Query(y) - Query(x - 1) << '\n';
}
}
Compilation message (stderr)
# | 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... |