# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
987127 | Sunbae | 원숭이와 사과 나무 (IZhO12_apple) | C++17 | 418 ms | 262144 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
struct Vertex{
Vertex *l = nullptr, *r = nullptr;
int low, high, sum = 0; bool op = false;
Vertex(int L, int R){low = L; high = R;}
~Vertex(){if(l) delete l; if(r) delete r;}
void propagate(){
if(low != high){
int mid = low + ((high-low)>>1);
if(!l) l = new Vertex(low, mid); if(!r) r = new Vertex(mid+1, high);
l->op = r->op = true;
}
op = false;
}
void upd(int L, int R){
if(op){sum = (high-low+1); propagate();}
if(low > R || high < L) return;
if(L <= low && high <= R){
sum = high-low+1; op = true; propagate(); return;
}
int mid = low + ((high-low)>>1);
if(!l) l = new Vertex(low, mid); if(!r) r = new Vertex(mid+1, high);
l->upd(L, R); r->upd(L, R);
sum = ((l)? l->sum : 0) + ((r)? r->sum : 0);
}
int qry(int L, int R){
if(op){sum = (high-low+1); propagate();}
if(low > R || high < L) return 0;
if(L <= low && high <= R) return sum;
int mid = low + ((high-low)>>1);
if(!l) l = new Vertex(low, mid); if(!r) r = new Vertex(mid+1, high);
return ((l)? l->qry(L, R) : 0) + ((r)? r->qry(L, R) : 0);
}
};
signed main(){
int q, c = 0; scanf("%d", &q);
Vertex* seg = new Vertex(1, 1e9);
while(q--){
int t, x, y; scanf("%d %d %d", &t, &x, &y);
if(t == 1){
printf("%d\n", c = seg->qry(x+c, y+c));
}else{
seg->upd(x+c, y+c);
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |