이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |