Pagini recente » Cod sursa (job #916225) | Cod sursa (job #640579) | Cod sursa (job #815681) | Cod sursa (job #1988450) | Cod sursa (job #1309177)
#include<fstream>
#include<algorithm>
using namespace std;
typedef struct lol {
int x,y,rs;
}troll;
int n,q,x,y,op;
troll arb[400005];
inline void Magic(int nod,int aux) { arb[nod].x=arb[nod].y=arb[nod].rs=aux; }
void update(int left,int right,int nod) {
if(x<=left && right<=y) (op==2) ? Magic(nod,right-left+1):Magic(nod,0);
else {
int pivot=(left+right)/2;
if(!arb[nod].rs) Magic(2*nod,0),Magic(2*nod+1,0);
if(arb[nod].rs==right-left+1) {
Magic(2*nod,pivot-left+1);
Magic(2*nod+1,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;
}