이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
struct node {
int s,e,m,v;
node *l, *r;
node (int _s, int _e){
s = _s; e = _e; m = (s+e)/2;
if (s != e){
l = new node (s,m);
r = new node (m+1,e);
}
}
void up(int x, int nv){
if (s == e) {v = nv; return;}
if (x > m) r -> up(x,nv);
if (x <= m) l -> up(x,nv);
v = l->v + r->v;
}
void spray(int x, int y, int k){
//printf("%lld %lld %lld %lld %lld\n",s,e,x,y,k);
if (s == e){
v /= k;
return;
}
else if (s == x && e == y){
if (v == 0) return;
l->spray(x,m,k);
r->spray(m+1,y,k);
v = l->v + r-> v;
}
else{
if (x > m) r -> spray(x,y,k);
else if (y <= m) l -> spray(x,y,k);
else l -> spray(x,m,k), r -> spray(m+1,y,k);
v = l->v + r->v;
}
}
int sum(int x, int y){
if (s == x && e == y) return v;
if (x > m) return r -> sum(x,y);
if (y <= m) return l -> sum(x,y);
return l->sum(x,m) + r->sum(m+1,y);
}
} *root;
main(){
int n,q,k;
scanf("%lld%lld%lld",&n,&q,&k);
root = new node (0,n-1);
for (int i = 0; i < n; i++){
int x;
scanf("%lld",&x);
root -> up(i,x);
}
for (int i = 0; i < q; i++){
int qu,a,b;
scanf("%lld%lld%lld",&qu,&a,&b);
if (qu == 1){
root -> up(--a,b);
}
else if (qu == 2){
root -> spray(--a,--b,k);
}
else if (qu == 3){
printf("%lld\n",root->sum(--a,--b));
}
//for (int i = 0; i < n; i++){
// printf("%lld ",root->sum(i,i));
//}
//printf("\n");
}
}
컴파일 시 표준 에러 (stderr) 메시지
sterilizing.cpp:46:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
sterilizing.cpp: In function 'int main()':
sterilizing.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld%lld",&n,&q,&k);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&x);
~~~~~^~~~~~~~~~~
sterilizing.cpp:57:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld%lld",&qu,&a,&b);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |