Pagini recente » Cod sursa (job #1662330) | Cod sursa (job #1726486) | Cod sursa (job #359307) | Cod sursa (job #1661140) | Cod sursa (job #2055936)
#include <fstream>
#define DIM 3*100000+5
using namespace std;
ifstream fi("hotel.in");
ofstream fo("hotel.out");
int n,p;
int tip,a,b;
int A[DIM]/*secv maxima cu camere libere*/,B[DIM]/*camere libere inceput*/, C[DIM]/*camere libere sfarsit*/;
void init(int nod,int l,int r)
{
if(l>r)
return;
if(l==r)
{
A[nod]=B[nod]=C[nod]=1;
return;
}
A[nod]=B[nod]=C[nod]=r-l+1;
init(nod*2,l,(l+r)/2);
init(2*nod+1,(l+r)/2+1,r);
}
void update(int nod,int st,int dr,int val,int l,int r)
{
if(st>r||dr<l)
return;
if(l<=st && dr<=r)
A[nod]=B[nod]=C[nod]=val*(dr-st+1);
else
{
if(A[nod]==0)
A[2*nod]=B[2*nod]=B[2*nod]=A[2*nod+1]=B[2*nod+1]=C[2*nod+1]=0;
if(A[nod]==dr-st+1)
{
A[2*nod]=B[2*nod]=C[2*nod]=(st+dr)/2-st+1;
A[2*nod+1]=B[2*nod+1]=C[2*nod+1]=dr-(st+dr)/2;
}
int mid=(st+dr)/2;
update(2*nod,st,mid,val,l,r);
update(2*nod+1,mid+1,dr,val,l,r);
B[nod]=B[2*nod];
if(B[2*nod]==mid-st+1)
B[nod]+=B[2*nod+1];
C[nod]=C[2*nod+1];
if(C[2*nod+1]==dr-mid)
C[nod]+=C[2*nod];
A[nod]=max(max(A[2*nod],A[2*nod+1]), C[2*nod]+B[2*nod+1]);
}
}
int main()
{
fi>>n>>p;
init(1,1,n);
for(int q=1; q<=p; q++)
{
fi>>tip;
if(tip==1||tip==2)
{
fi>>a>>b;
int u=0;
if(tip==2) u=1;
update(1,1,n,u,a,a+b-1);
}
else
fo<<A[1]<<"\n";
}
fi.close();
fo.close();
return 0;
}