Pagini recente » Cod sursa (job #2390212) | Cod sursa (job #2469524) | Cod sursa (job #3132792) | Cod sursa (job #379994) | Cod sursa (job #2117658)
#include <fstream>
using namespace std;
int n,p,tip,inc,sf,A[300005],B[300005],C[300005];
void init(int nod, int st, int dr)
{
A[nod]=B[nod]=C[nod]=dr-st+1;
if(st==dr) return;
int m=st+(dr-st)/2;
init(2*nod,st,m);
init(2*nod+1,m+1,dr);
}
void update(int nod, int st, int dr,int val,int a,int b)
{
if(a<=st && dr<=b)
{
A[nod]=B[nod]=C[nod]=val*(dr-st+1);
return;
}
int m=st+(dr-st)/2;
if(A[nod]==0)
A[2*nod]=B[2*nod]=C[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]=m-st+1;
A[2*nod+1]=B[2*nod+1]=C[2*nod+1]=dr-m;
}
if(a<=m) update(2*nod,st,m,val,a,b);
if(m<b) update(2*nod+1,m+1,dr,val,a,b);
B[nod]=B[2*nod];
if(B[2*nod]==m-st+1) B[nod]+=B[2*nod+1];
C[nod]=C[2*nod+1];
if(C[2*nod+1]==dr-m) 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()
{
ifstream cin("hotel.in");
ofstream cout("hotel.out");
cin>>n>>p;
init(1,1,n);
for(int q=1; q<=p; q++)
{
cin>>tip;
if(tip==1||tip==2)
{
cin>>inc>>sf;
int u=0;
if(tip==2) u=1;
update(1,1,n,u,inc,sf+inc-1);
}
else
cout<<A[1]<<"\n";
}
return 0;
}