# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
91811 | SamAnd | 원숭이와 사과 나무 (IZhO12_apple) | C++17 | 187 ms | 3192 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
const int N=100005,M=1000000000;
int t[N*120];
int ll[N*120],rr[N*120];
int z;
void ubd(int tl,int tr,int l,int r,int pos)
{
if(t[pos]==(tr-tl+1))
return;
if(tl==l && r==tr)
{
t[pos]=r-l+1;
return;
}
int m=(tl+tr)/2;
if(r<=m)
{
if(!ll[pos])
ll[pos]=++z;
ubd(tl,m,l,r,ll[pos]);
}
else if(l>m)
{
if(!rr[pos])
rr[pos]=++z;
ubd(m+1,tr,l,r,rr[pos]);
}
else
{
if(!ll[pos])
ll[pos]=++z;
if(!rr[pos])
rr[pos]=++z;
ubd(tl,m,l,m,ll[pos]);
ubd(m+1,tr,m+1,r,rr[pos]);
}
t[pos]=0;
if(ll[pos])
t[pos]+=t[ll[pos]];
if(rr[pos])
t[pos]+=t[rr[pos]];
}
int qry(int tl,int tr,int l,int r,int pos)
{
if(t[pos]==(tr-tl+1))
return (r-l+1);
if(tl==l && tr==r)
return t[pos];
int m=(tl+tr)/2;
if(r<=m)
{
if(!ll[pos])
return 0;
return qry(tl,m,l,r,ll[pos]);
}
else if(l>m)
{
if(!rr[pos])
return 0;
return qry(m+1,tr,l,r,rr[pos]);
}
else
{
if(!ll[pos] && !rr[pos])
return 0;
else if(ll[pos] && !rr[pos])
return qry(tl,m,l,m,ll[pos]);
else if(!ll[pos] && rr[pos])
return qry(m+1,tr,m+1,r,rr[pos]);
else
return qry(tl,m,l,m,ll[pos])+qry(m+1,tr,m+1,r,rr[pos]);
}
}
int main()
{
//freopen("f.in","r",stdin);
//freopen("f.out","w",stdout);
int q;
cin>>q;
int c=0;
while(q--)
{
int z,x,y;
cin>>z>>x>>y;
x+=c;
y+=c;
if(z==1)
{
int ans=qry(1,M,x,y,0);
cout<<ans<<endl;
c=ans;
}
else
{
ubd(1,M,x,y,0);
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |