# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
13299 | dohyun0324 | 원숭이와 사과 나무 (IZhO12_apple) | C++98 | 59 ms | 1224 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<stdio.h>
#include<algorithm>
using namespace std;
#define M 1000000000
int st,en,n,d,x,y;
struct data
{
int value,s,e;
data *l,*r;
data(){}
data(int v,int s,int e):value(v),s(s),e(e){
l=r=NULL;
}
void update(int x,int y)
{
if(x>en || y<st) return;
if(value==y-x+1){
return;
}
if(st<=x && y<=en){
value=y-x+1; return;
}
int m=(s+e)/2;
if(l==NULL)
l=new data(0,s,m);
if(r==NULL)
r=new data(0,m+1,e);
l->update(s,m); r->update(m+1,e);
value=l->value+r->value;
}
int query(int x,int y)
{
if(x>en || y<st) return 0;
if(value==y-x+1)
{
return min(y,en)-max(x,st)+1;
}
if(st<=x && y<=en) return value;
int m=(s+e)/2;
if(l==NULL) l=new data(0,s,m);
if(r==NULL) r=new data(0,m+1,e);
return l->query(s,m)+r->query(m+1,e);
}
};
int main()
{
int i,c=0;
scanf("%d",&n);
data start=data(0,1,M);
for(i=1;i<=n;i++)
{
scanf("%d %d %d",&d,&x,&y);
if(d==2)
{
st=x+c; en=y+c;
start.update(1,M);
}
else
{
st=x+c; en=y+c;
c=start.query(1,M);
printf("%d\n",c);
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |