Pagini recente » Cod sursa (job #652692) | Cod sursa (job #1402347) | Cod sursa (job #2625613) | Cod sursa (job #639772) | Cod sursa (job #1309176)
#include<fstream>
#include<algorithm>
using namespace std;
typedef struct lol {
int x,y,rs;
}troll;
int n,q,x,y,op;
troll arb[400005];
void update(int left,int right,int nod) {
if(x<=left && right<=y) arb[nod].x=arb[nod].y=arb[nod].rs=(op==2) ? right-left+1:0;
else {
int pivot=(left+right)/2;
/* if(!arb[nod].rs) {
arb[2*nod].x=arb[2*nod].y=arb[2*nod].rs=0;
arb[2*nod+1].x=arb[2*nod+1].y=arb[2*nod+1].rs=0;
}*/
if(arb[nod].rs==right-left+1) {
arb[2*nod].x=arb[2*nod].y=arb[2*nod].rs=pivot-left+1;
arb[2*nod+1].x=arb[2*nod+1].y=arb[2*nod+1].rs=right-pivot;
}
if(x<=pivot) update(left,pivot,2*nod);
if(pivot<y) update(pivot+1,right,2*nod+1);
arb[nod].rs=max(arb[2*nod].rs,arb[2*nod+1].rs);
arb[nod].rs=max(arb[nod].rs,arb[2*nod].y+arb[2*nod+1].x);
arb[nod].x=arb[2*nod].x;
arb[nod].y=arb[2*nod+1].y;
if(arb[2*nod].x==pivot-left+1) arb[nod].x+=arb[2*nod+1].x;
if(arb[2*nod+1].y==right-pivot) arb[nod].y+=arb[2*nod].y;
}
}
int main()
{
ifstream cin("hotel.in");
ofstream cout("hotel.out");
cin>>n>>q; op=2;
x=1; y=n; update(1,n,1);
while(q--)
{
cin>>op;
if(op==3) cout<<arb[1].rs<<'\n';
else cin>>x>>y,y+=x-1,update(1,n,1);
}
return 0;
}