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;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
struct ST{
vector<ll> t;
int n;
ST(int ns){
n = ns;
t.resize(4 * n);
}
void upd(int v, int tl, int tr, int& p, int& x){
if (tl == tr){
t[v] = x;
return;
}
int tm = (tl + tr) / 2, vv = 2 * v;
if (p <= tm){
upd(vv, tl, tm, p, x);
}
else {
upd(vv + 1, tm + 1, tr, p, x);
}
t[v] = t[vv] + t[vv + 1];
}
void upd(int p, int x){
upd(1, 1, n, p, x);
}
ll get(int v, int tl, int tr, int& l, int& r){
if (l > tr || r < tl) return 0;
if (l <= tl && tr <= r) return t[v];
int tm = (tl + tr) / 2, vv = 2 * v;
return get(vv, tl, tm, l, r) + get(vv + 1, tm + 1, tr, l, r);
}
ll get(int l, int r){
return get(1, 1, n, l, r);
}
};
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q, k; cin>>n>>q>>k;
vector<int> a(n + 1);
ST T(n);
set<int> st;
for (int i = 1; i <= n; i++){
cin>>a[i];
T.upd(i, a[i]);
if (a[i]){
st.insert(i);
}
}
vector<int> all;
while (q--){
int s, x, y; cin>>s>>x>>y;
if (s == 1){
T.upd(x, y);
auto it = st.find(x);
if (it != st.end()){
st.erase(it);
}
if (y) st.insert(x);
a[x] = y;
}
else if (s == 2){
if (k == 1) continue;
auto it = st.lower_bound(x);
all.clear();
while (it != st.end() && (*it) <= y){
all.pb((*it));
it++;
}
for (int j: all){
a[j] /= k;
T.upd(j, a[j]);
if (!a[j]){
st.erase(j);
}
}
}
else {
cout<<T.get(x, y)<<"\n";
}
}
}
# | 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... |