Pagini recente » Cod sursa (job #2453709) | Cod sursa (job #824185) | Cod sursa (job #2222206) | Cod sursa (job #1806380) | Cod sursa (job #2774030)
#include <fstream>
using namespace std;
ifstream in("hotel.in");
ofstream out("hotel.out");
const int NMAX=(1 << 18);
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()
{
ios::sync_with_stdio(false);
in>>n>>p;
init(1,n,1);
for(;p>=1;p--)
{
in>>c;
if(c==3)
out<<arb[1]<<'\n';
else
{
in>>a>>b;
b=a+b-1;
update(1,n,1,c);
}
}
in.close();
out.close();
return 0;
}