Pagini recente » Cod sursa (job #2559054) | Cod sursa (job #1988868) | Cod sursa (job #1945219) | Cod sursa (job #2839877) | Cod sursa (job #2774013)
#include <fstream>
#define NMAX 100005
using namespace std;
ifstream cin("hotel.in");
ofstream cout("hotel.out");
int n,p,c,a,b;
int arb[4*NMAX],arbst[4*NMAX],arbdr[4*NMAX];
void init(int st, int dr, int poz)
{
if(st==dr)
{
arb[poz]=arbst[poz]=arbdr[poz]=1;
}
else
{
int mij=(st+dr)/2;
init(st,mij,2*poz);
init(mij+1,dr,2*poz+1);
arb[poz]=arbst[poz]=arbdr[poz]=dr-st+1;
}
}
void update(int st, int dr, int poz, int tip)
{
if(st==dr)
{
if(tip==1)
arb[poz]=arbst[poz]=arbdr[poz]=0;
else
arb[poz]=arbst[poz]=arbdr[poz]=1;
}
else
{
int mij=(st+dr)/2;
if(a<=mij)
update(st,mij,2*poz,tip);
if(b>=mij+1)
update(mij+1,dr,2*poz+1,tip);
if(arbst[2*poz]==mij-st+1)
arbst[poz]=arbst[2*poz]+arbst[2*poz+1];
else
arbst[poz]=arbst[2*poz];
if(arbdr[2*poz+1]==dr-mij)
arbdr[poz]=arbdr[2*poz+1]+arbdr[2*poz];
else
arbdr[poz]=arbdr[2*poz+1];
arb[poz]=max(arbdr[2*poz]+arbst[2*poz+1],max(arb[2*poz],arb[2*poz+1]));
}
}
int main()
{
cin>>n>>p;
init(1,n,1);
for(;p>=1;p--)
{
cin>>c;
if(c==3)
cout<<arb[1]<<'\n';
else
{
cin>>a>>b;
b=a+b-1;
update(1,n,1,c);
}
}
return 0;
}