# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
548634 | ac2hu | 원숭이와 사과 나무 (IZhO12_apple) | C++14 | 552 ms | 262144 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
struct node{
node* child[2];
int lazy, sum;
int tl,tr;
node(int l, int r){
lazy = 0;
sum = 0;
tl = l;
tr = r;
child[0] = child[1] = NULL;
};
void add(){
int tm = (tl + tr)/2;
if(!child[0])
child[0] = new node(tl, tm);
if(!child[1])
child[1] = new node(tm + 1, tr);
}
int siz(){
return tr - tl + 1;
}
};
node *root = new node(1, 1e9);
void push(node* v){
if(v->lazy == 0 || v->tl == v->tr)return;
int tm = (v->tl + v->tr)/2;
v->add();
v->child[0]->lazy = 1;
v->child[1]->lazy = 1;
v->lazy= 0;
v->child[0]->sum = v->child[0]->siz();
v->child[1]->sum = v->child[1]->siz();
}
void update(int l,int r,node *v){
push(v);
if(l > r || !v)
return;
else if(l == v->tl && r == v->tr){
int siz = v->tr - v->tl + 1;
v->lazy = 1;
v->sum = siz;
}
else{
int tm = (v->tl + v->tr)/2;
v->add();
update(l, min(tm,r), v->child[0]);
update(max(l,tm + 1), r, v->child[1]);
v->sum = v->child[0]->sum + v->child[1]->sum;
}
}
int query(int l,int r,node* v){
push(v);
if(l > r || !v)
return 0;
else if(l == v->tl && r == v->tr)
return v->sum;
else{
int tm = (v->tl + v->tr)/2;
v->add();
return query(l, min(tm, r), v->child[0]) + query(max(l,tm + 1), r, v->child[1]);
}
}
int main(){
int q;cin >> q;
int c = 0;
while(q--){
int d, x, y;cin >> d >> x >> y;
x += c;y+=c;
if(d == 1){
cout << (c = query(x,y,root)) << "\n";
}
else{
update(x,y,root);
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |