이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
# include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2;
int n, q, k, a[N];
long long t[N * 4], mx[N * 4];
void upd(int pos, int val, int v = 1, int tl = 1, int tr = n){
if(tl == tr){
t[v] = val;
mx[v] = val;
} else {
int tm = (tl + tr) >> 1;
if(pos <= tm)
upd(pos, val, v << 1, tl, tm);
else
upd(pos, val, v << 1 | 1, tm + 1, tr);
t[v] = t[v << 1] + t[v << 1 | 1];
mx[v] = max(mx[v << 1], mx[v << 1 | 1]);
}
}
void upd1(int l, int r, int v = 1, int tl = 1, int tr = n){
if(l > tr || tl > r || mx[v] < 1)
return ;
if(tl == tr){
t[v] = t[v] / k;
mx[v] = t[v];
return ;
}
int tm = (tl + tr) >> 1;
upd1(l, r, v << 1, tl, tm);
upd1(l, r, v << 1 | 1, tm + 1, tr);
t[v] = t[v << 1] + t[v << 1 | 1];
mx[v] = max(mx[v << 1], mx[v << 1 | 1]);
}
long long get(int l, int r, int v = 1, int tl = 1, int tr = n){
if(l > tr || tl > r)
return 0;
if(l <= tl && tr <= r)
return t[v];
int tm = (tl + tr) >> 1;
return get(l, r, v << 1, tl, tm) +
get(l, r, v << 1 | 1, tm + 1, tr);
}
int main(){
cin >> n >> q >> k;
for(int i = 1; i <= n; i ++){
scanf("%d", a+i);
upd(i, a[i]);
}
while(q --){
int tp, l, r;
scanf("%d %d %d", &tp, &l, &r);
if(tp == 1)
upd(l, r);
if(tp == 2 && k > 1)
upd1(l, r);
if(tp == 3)
printf("%lld\n", get(l, r));
}
}
컴파일 시 표준 에러 (stderr) 메시지
sterilizing.cpp: In function 'int main()':
sterilizing.cpp:54:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", a+i);
~~~~~^~~~~~~~~~~
sterilizing.cpp:60:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &tp, &l, &r);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |