Pagini recente » Cod sursa (job #1548420) | Cod sursa (job #2123525) | Cod sursa (job #2563402) | Cod sursa (job #2970078) | Cod sursa (job #549295)
Cod sursa(job #549295)
#include<fstream>
#include<vector>
using namespace std;
ifstream fin("hotel.in");
ofstream fout("hotel.out");
int n, m, start, finish, v;
int a[400002], b[400002], c[400002];
bool s[400002];
void Read();
void Initializare( int nod, int st, int dr )
{
a[nod] = b[nod] = c[nod] = dr-st+1;
if( st == dr )
return;
int mij = (st+dr)/2;
Initializare( 2*nod, st, mij );
Initializare( 2*nod+1, mij+1, dr );
}
void Update(int nod, int st, int dr );
int main()
{
Read();
fin.close();
fout.close();
return 0;
}
void Read()
{
fin >> n >> m;
int x, y, t;
Initializare(1, 1, n );
for( int i = 1; i <= m; ++i )
{
fin >> t;
if( t == 1 )
{
fin >> x >> y;
v = 0;
start = x;
finish = x+y-1;
Update( 1, 1, n );
}
if( t == 2 )
{
fin >> x >> y;
v = 1;
start = x;
finish = x+y-1;
Update(1, 1, n);
}
if( t == 3 )
{
if( i == 1 )
fout << n << '\n';
else
fout << a[1] << '\n';
}
}
}
void Update(int nod, int st, int dr )
{
if( st==start && dr == finish )
{
a[nod] = b[nod] = c[nod] = v * (dr-st+1);
return;
}
if( st == dr )
{
a[nod] = v;
b[nod] = v;
c[nod] = v;
return;
}
int mij = (st+dr) >> 1;
int stnod = (nod << 1);
int drnod = stnod + 1;
if( a[nod] == dr-st+1 )
{
a[stnod] = b[stnod] = c[stnod] = mij - st + 1;
a[drnod] = b[drnod] = c[drnod] = dr - mij;
}
if( a[nod] == 0 )
{
a[stnod] = b[stnod] = c[stnod] = 0;
a[drnod] = b[drnod] = c[drnod] = 0;
}
if( start <= mij )
Update( stnod, st, mij );
if( finish > mij )
Update( drnod, mij+1, dr );
if( b[stnod] == (dr - st + 1)- (dr - mij) )
b[nod] = b[stnod] + b[drnod];
else
b[nod] = b[stnod];
if( b[drnod] == dr - mij )
c[nod] = c[stnod] + b[drnod];
else
c[nod] = c[drnod];
a[nod] = max( max(c[stnod] + b[drnod], max( a[stnod], a[drnod] ) ), max( b[nod], c[nod]) );
}