Pagini recente » Cod sursa (job #2189112) | Cod sursa (job #2152224) | Cod sursa (job #174717) | Cod sursa (job #1362732) | Cod sursa (job #549271)
Cod sursa(job #549271)
#include<fstream>
#include<vector>
using namespace std;
ifstream fin("hotel.in");
ofstream fout("hotel.out");
int n, m, start, finish, v;
int a[400020], b[400020], c[400020];
bool s[400020];
void Read();
/*
void Initializare( int nod, int st, int dr )
{
if( st == dr )
{
a[nod] = b[nod] = c[nod] = 1;
return;
}
int mij = (st+dr)/2;
int stnod = (nod << 1);
int drnod = stnod + 1;
Initializare( stnod, st, mij );
Initializare( drnod, mij+1, dr );
a[nod] = b[nod] = c[nod] = a[stnod] + a[drnod];
}
*/
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( !s[nod] )
{
s[nod] = true;
a[nod] = b[nod] = c[nod] = st-dr+1;
if(2*nod+1 < 400020 )
{
a[2*nod] = b[2*nod] = c[2*nod] = (dr - st + 1)- (dr - (st+dr)/2 );
a[2*nod+1] = b[2*nod+1] = c[2*nod+1] = dr - (st+dr)/2;
}
}
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( start <= mij )
{
/*
if( !s[2*nod] )
{
s[2*nod] = true;
a[2*nod] = b[2*nod] = c[2*nod] = (dr - st + 1)- (dr - (st+dr)/2 );
}
*/
Update( stnod, st, mij );
}
if( finish > mij )
{
/*
if( !s[2*nod+1] )
{
s[2*nod+1] = true;
a[2*nod+1] = b[2*nod+1] = c[2*nod+1] = dr - (st+dr)/2;
}
*/
Update( drnod, mij+1, dr );
}
if( b[stnod] == (dr - st + 1)- (dr - mij) )
{
b[nod] = b[stnod] + b[drnod];
if( a[nod] < b[nod] )
a[nod] = b[nod];
}
else
{
b[nod] = b[stnod];
if( a[nod] < b[nod] )
a[nod] = b[nod];
}
if( b[drnod] == dr - mij )
{
c[nod] = c[stnod] + b[drnod];
if( a[nod] < c[nod] )
a[nod] = c[nod];
}
else
{
c[nod] = c[drnod];
if( a[nod] < c[nod] )
a[nod] = c[nod];
}
a[nod] = max( c[stnod] + b[drnod], max( a[stnod], a[drnod] ) );
}