Pagini recente » Cod sursa (job #413528) | Cod sursa (job #419948) | Cod sursa (job #1037084) | Cod sursa (job #2127197) | Cod sursa (job #2055892)
#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*/,N[DIM]/*numarul total de camere*/;
void init(int nod,int l,int r)
{
if(l>r)
return;
if(l==r)
{
A[nod]=B[nod]=C[nod]=N[nod]=1;
return;
}
A[nod]=B[nod]=C[nod]=N[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(dr<l||st>r)
return;
if(st == dr)
A[nod]=B[nod]=C[nod]=val;
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;
}
update(2*nod,st,(st+dr)/2,val,l,r);
update(2*nod+1,(st+dr)/2+1,dr,val,l,r);
B[nod]=B[2*nod];
if(B[2*nod]==N[2*nod])
B[nod]+=B[2*nod+1];
C[nod]=C[2*nod+1];
if(C[2*nod+1]==N[2*nod+1])
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 q=0;
if(tip==2) q=1;
update(1,1,n,q,a,a+b-1);
}
else
fo<<A[1]<<"\n";
}
fi.close();
fo.close();
return 0;
}