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;
#define ll long long
// #define int long long
#define endl '\n'
#define all(x) x.begin(),x.end()
const ll MOD = 1e9 + 7, SZ = 1e5 + 10, INF = 1e18;
int N = 1 << 18, t[1 << 19];
void upd(int i, int v){
i += N;
t[i] = v;
for(i/=2;i;i/=2)
t[i] = t[i * 2] + t[i * 2 + 1];
}
int clc(int l, int r, int i = 1, int from = 1, int to = N){
if(from > r || to < l)
return 0;
if(from >= l && to <= r)
return t[i];
int mid = (from + to)/2;
return clc(l, r, i*2, from, mid) + clc(l, r, i*2 + 1, mid + 1, to);
}
int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, q, k;
cin >> n >> q >> k;
int arr[n];
set<int> st;
for(int i=0;i<n;i++){
cin >> arr[i];
upd(i, arr[i]);
if(arr[i])
st.insert(i + 1);
}
while(q--){
int t, l, r;
cin >> t >> l >> r;
if(t == 1){
arr[l - 1] = r;
upd(l - 1, r);
if(r)
st.insert(l);
}
else if(t == 3)
cout << clc(l, r) << endl;
else if(k != 1){
while(l <= r){
auto x = st.lower_bound(l);
if(x == st.end() || *x > r)
break;
arr[*x - 1] /= k;
upd(*x - 1, arr[*x - 1]);
if(arr[*x - 1] == 0)
st.erase(*x);
l = *x + 1;
}
}
}
return 0;
}
# | 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... |