Pagini recente » Cod sursa (job #2894873) | Cod sursa (job #3129411) | Cod sursa (job #2168967) | Cod sursa (job #2357365) | Cod sursa (job #600829)
Cod sursa(job #600829)
#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);
}
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;
}