Pagini recente » Cod sursa (job #2360287) | Cod sursa (job #3239867) | Cod sursa (job #211109) | Cod sursa (job #266269) | Cod sursa (job #548470)
Cod sursa(job #548470)
#include<fstream>
#include<vector>
using namespace std;
ifstream fin("hotel.in");
ofstream fout("hotel.out");
int n, m, start, finish;
vector<pair<int, pair<int, int> > > arb;
void Read();
void Initializare(int nod, int st, int dr );
void Update(int nod, int st, int dr );
void Update1(int nod, int st, int dr );
int main()
{
Read();
fin.close();
fout.close();
return 0;
}
void Read()
{
fin >> n >> m;
int a, b, t;
int l = 4*n;
arb.resize(l+2);
Initializare(1, 1, n );
for( int i = 1; i <= m; ++i )
{
fin >> t;
if( t == 1 )
{
fin >> a >> b;
start = a;
finish = a+b-1;
Update( 1, 1, n );
}
if( t == 2 )
{
fin >> a >> b;
start = a;
finish = a+b-1;
Update1(1, 1, n);
}
if( t == 3 )
fout << arb[1].first << '\n';
}
/*
for( int i = 1; i <= l; ++i )
fout << arb[i].first << ' ' << arb[i].second.first << ' ' << arb[i].second.second << '\n';
*/
}
void Update(int nod, int st, int dr )
{
if( st == dr )
{
arb[nod].first = 0;
arb[nod].second.first = 0;
arb[nod].second.second = 0;
return;
}
int mij = (st+dr)/2;
if( start <= mij )
Update( 2*nod, st, mij );
if( finish > mij )
Update( 2*nod+1, mij+1, dr );
arb[nod].second.first = arb[2*nod].second.first;
arb[nod].second.second = arb[2*nod+1].second.second;
if( arb[2*nod].second.first == (dr- st + 1)- (dr - mij) && arb[2*nod].second.first != 0 )
arb[nod].second.first = arb[2*nod].second.first + arb[2*nod+1].second.first;
if( arb[2*nod+1].second.first == dr - mij && arb[2*nod+1].second.first != 0 )
arb[nod].second.second = arb[2*nod].second.second + arb[2*nod+1].second.first;
arb[nod].first = max( arb[2*nod].first, arb[2*nod+1].first );
if( arb[nod].first < arb[nod].second.first )
arb[nod].first = arb[nod].second.first;
if( arb[nod].first < arb[nod].second.second )
arb[nod].first = arb[nod].second.second;
if( arb[nod].first < arb[2*nod].second.second + arb[2*nod+1].second.first )
arb[nod].first = arb[2*nod].second.second + arb[2*nod+1].second.first;
}
void Update1(int nod, int st, int dr )
{
if( st == dr )
{
arb[nod].first = 1;
arb[nod].second.first = 1;
arb[nod].second.second = 1;
return;
}
int mij = (st + dr) / 2;
if( start <= mij )
Update1( 2*nod, st, mij );
if( finish > mij )
Update1( 2*nod+1, mij+1, dr );
arb[nod].second.first = arb[2*nod].second.first;
arb[nod].second.second = arb[2*nod+1].second.second;
if( arb[2*nod].second.first == (dr- st + 1)- (dr - mij) /*&& arb[2*nod].second.first != 0 */)
arb[nod].second.first = arb[2*nod].second.first + arb[2*nod+1].second.first;
if( arb[2*nod+1].second.first == dr - mij /*&& arb[2*nod+1].second.first != 1 */)
arb[nod].second.second = arb[2*nod].second.second + arb[2*nod+1].second.second;
arb[nod].first = max( arb[2*nod].first, arb[2*nod+1].first );
if( arb[nod].first < arb[nod].second.first )
arb[nod].first = arb[nod].second.first;
if( arb[nod].first < arb[nod].second.second )
arb[nod].first = arb[nod].second.second;
if( arb[nod].first < arb[2*nod].second.second + arb[2*nod+1].second.first )
arb[nod].first = arb[2*nod].second.second + arb[2*nod+1].second.first;
/*
arb[nod].second.first = arb[2*nod].second.first;
arb[nod].second.second = arb[2*nod+1].second.second;
if( arb[2*nod].second.first == mij - st )
arb[nod].second.first = arb[2*nod].second.first + arb[2*nod+1].second.first;
if( arb[2*nod+1].second.first == dr - mij )
arb[nod].second.second = arb[2*nod].second.second + arb[2*nod+1].second.first;
arb[nod].first = max( arb[2*nod].first, arb[2*nod+1].first );
if( arb[nod].first < arb[nod].second.first )
arb[nod].first = arb[nod].second.first;
if( arb[nod].first < arb[nod].second.second )
arb[nod].first = arb[nod].second.second;
*/
}
void Initializare( int nod, int st, int dr )
{
if( st == dr )
{
arb[nod].first = 1;
arb[nod].second.first = 1;
arb[nod].second.second = 1;
return;
}
int mij = (st+dr)/2;
Initializare( 2*nod, st, mij );
Initializare( 2*nod+1, mij+1, dr );
arb[nod].first = arb[2*nod].first + arb[2*nod+1].first;
arb[nod].second.first = arb[2*nod].second.first + arb[2*nod+1].second.first;
arb[nod].second.second = arb[2*nod].second.second + arb[2*nod+1].second.second;
}