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;
const int N = 1e5 + 10;
int n, K, m;
long long pw[N];
struct SegmentTree{
int mx[N << 3];
long long sum[N << 3];
#define mid ((l + r) >> 1)
void modify(int x, int l, int r, int u, int val){
if(l > u || r < u) return;
if(l == r){
sum[x] = mx[x] = val;
return;
}
modify(x + x, l, mid, u, val);
modify(x + x + 1, mid + 1, r, u, val);
sum[x] = sum[x + x] + sum[x + x + 1];
mx[x] = max(mx[x + x], mx[x + x + 1]);
}
void update(int x, int l, int r, int u, int v){
if(l > v || r < u || mx[x] == 0) return;
if(l == r){
sum[x] /= K;
mx[x] /= K;
return;
}
update(x + x, l, mid, u, v);
update(x + x + 1, mid + 1, r, u, v);
sum[x] = sum[x + x] + sum[x + x + 1];
mx[x] = max(mx[x + x], mx[x + x + 1]);
}
long long query(int x, int l, int r, int u, int v){
if(l > v || r < u) return 0;
if(l >= u && r <= v) return sum[x];
return query(x + x, l, mid, u, v) + query(x + x + 1, mid + 1, r, u, v);
}
}Smt;
int main(){
if(fopen("1.inp", "r")){
freopen("1.inp", "r", stdin);
}
scanf("%d%d%d", &n, &m, &K);
pw[0] = 1;
for(int i = 1; i <= m; ++i){
if(1e18 / pw[i - 1] < K) pw[i] = 1e18;
else pw[i] = pw[i - 1] * K;
}
for(int i = 1; i <= n; ++i){
int x;
scanf("%d", &x);
Smt.modify(1, 1, n, i, x);
}
while(m--){
int t, u, v;
scanf("%d%d%d", &t, &u, &v);
if(t == 1){
Smt.modify(1, 1, n, u, v);
}
if(t == 2 && K > 1){
Smt.update(1, 1, n, u, v);
}
if(t == 3){
printf("%lld\n", Smt.query(1, 1, n, u, v));
}
}
return 0;
}
Compilation message (stderr)
sterilizing.cpp: In function 'int main()':
sterilizing.cpp:51:31: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen("1.inp", "r", stdin);
^
sterilizing.cpp:54:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &n, &m, &K);
^
sterilizing.cpp:66:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &x);
^
sterilizing.cpp:73:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &t, &u, &v);
^
# | 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... |