Pagini recente » Cod sursa (job #1951222) | Cod sursa (job #1627323) | Cod sursa (job #1398121) | Cod sursa (job #826118) | Cod sursa (job #600833)
Cod sursa(job #600833)
#include <fstream>
using namespace std;
const int N = (1<<18);
ifstream in("hotel.in");
//ofstream out("hotel.out");
struct nod
{
int st,dr,max;
};
int n, a, b;
nod t[N];
inline int max(int x, int y)
{
return x>y ? x : y;
}
/*
void modifica(int tip, int p, int st, int dr)
{
if(st == dr)
{
if(tip == 1)
t[p].st = t[p].dr = t[p].max = 0;
else
t[p].st = t[p].dr = t[p].max = dr - st + 1;
return;
}
int mij = (st + dr) >> 1;
if(t[p].max == dr-st+1)
{
t[p<<1].st = t[p<<1].dr = t[p<<1].max = mij - st + 1;
t[(p<<1)+1].st = t[(p<<1)+1].dr = t[(p<<1)+1].max = dr - mij;
}
if(t[p].max == 0)
{
t[p<<1].st = t[p<<1].dr = t[p<<1].max = 0;
t[(p<<1)+1].st = t[(p<<1)+1].dr = t[(p<<1)+1].max = 0;
}
if(a <= mij)
modifica(tip, p<<1, st, mij);
if(b > mij)
modifica(tip, (p<<1)+1, mij+1, dr);
t[p].st = t[p<<1].st;
if(t[p<<1].st == mij - st + 1)
t[p].st += t[(p<<1)+1].st;
t[p].dr = t[(p<<1)+1].dr;
if(t[(p<<1)+1].dr == dr - mij)
t[p].dr += t[p<<1].dr;
t[p].max = max(max(t[p<<1].max, t[(p<<1)+1].max), t[p<<1].dr + t[(p<<1)+1].st);
}
*/
void modifica(int tip,int poz,int st,int dr)
{
if(a<=st && dr<=b)
{
if(tip==1)
t[poz].st=t[poz].dr=t[poz].max=0;
else
t[poz].st=t[poz].dr=t[poz].max=dr-st+1;
return;
}
int mid=(st+dr)>>1;
if(t[poz].max==dr-st+1)
{
t[poz<<1].st=t[poz<<1].dr=t[poz<<1].max=mid-st+1;
t[(poz<<1)+1].st=t[(poz<<1)+1].dr=t[(poz<<1)+1].max=dr-mid;
}
if(t[poz].max==0)
{
t[poz<<1].st=t[poz<<1].dr=t[poz<<1].max=0;
t[(poz<<1)+1].st=t[(poz<<1)+1].dr=t[(poz<<1)+1].max=0;
}
if(a<=mid)
modifica(tip,poz<<1,st,mid);
if(b>mid)
modifica(tip,(poz<<1)+1,mid+1,dr);
t[poz].st=t[poz<<1].st;
if(t[poz<<1].max==mid-st+1)
t[poz].st+=t[(poz<<1)+1].st;
t[poz].dr=t[(poz<<1)+1].dr;
if(t[(poz<<1)+1].max==dr-mid)
t[poz].dr+=t[poz<<1].dr;
t[poz].max=max(t[poz<<1].dr+t[(poz<<1)+1].st,max(t[poz<<1].max,t[(poz<<1)+1].max));
}
int main()
{
freopen("hotel.out", "w", stdout);
int m,tip,nr;
in>>n>>m;
t[1].st = t[1].dr = t[1].max = n;
while(m--)
{
in>>tip;
if(tip == 1 || tip == 2)
{
in>>a>>nr;
b = a + nr - 1;
modifica(tip, 1, 1, n);
continue;
}
//out<<t[1].max<<"\n";
printf("%d\n",t[1].max);
}
return 0;
}