# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
13303 | baneling100 | Monkey and Apple-trees (IZhO12_apple) | C++98 | 437 ms | 134136 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#define INF 1073741824
struct node {
node() : left(NULL), right(NULL), cnt(NULL), lazy(NULL) {}
node *left, *right;
int cnt, lazy;
} *Root;
int M, D, X, Y, C;
void countApple(int left, int right, node *now) {
int mid=(left+right)/2;
if(X<=left && right<=Y)
C+=now->cnt;
else {
if(!now->left ) now->left =new node();
if(!now->right) now->right=new node();
if(now->lazy) {
now->left ->cnt =mid-left+1;
now->left ->lazy=1;
now->right->cnt =right-mid;
now->right->lazy=1;
}
if(X<=mid) countApple(left ,mid ,now->left );
if(mid+1<=Y) countApple(mid+1,right,now->right);
if(!now->lazy) {
if(now->left->lazy && now->right->lazy) {
now->cnt =right-left+1;
now->lazy=1;
}
else now->cnt=now->left->cnt+now->right->cnt;
}
}
}
void ripeApple(int left, int right, node *now) {
int mid=(left+right)/2;
if(X<=left && right<=Y) {
now->cnt =right-left+1;
now->lazy=1;
}
else {
if(!now->left ) now->left =new node();
if(!now->right) now->right=new node();
if(now->lazy) {
now->left ->cnt =mid-left+1;
now->left ->lazy=1;
now->right->cnt =right-mid;
now->right->lazy=1;
}
if(X<=mid) ripeApple(left ,mid ,now->left );
if(mid+1<=Y) ripeApple(mid+1,right,now->right);
if(!now->lazy) {
if(now->left->lazy && now->right->lazy) {
now->cnt =right-left+1;
now->lazy=1;
}
else now->cnt=now->left->cnt+now->right->cnt;
}
}
}
int main(void) {
int i;
Root=new node();
scanf("%d",&M);
for(i=1 ; i<=M ; i++) {
scanf("%d %d %d",&D,&X,&Y);
X+=C, Y+=C;
if(D==1) {
C=0;
countApple(1,INF,Root);
printf("%d\n",C);
}
else
ripeApple(1,INF,Root);
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |