Pagini recente » Cod sursa (job #59641) | Cod sursa (job #1825682) | Cod sursa (job #401163) | Cod sursa (job #2563059) | Cod sursa (job #774765)
Cod sursa(job #774765)
#include <stdio.h>
#include <algorithm>
#include <set>
using namespace std;
#define point pair<int, int>
#define INF 2000000000
set<point> S1, S2;
multiset<int> S3;
int N, P, Tip, X, Y;
int i;
inline point opus(const point &a)
{
return make_pair(-a.first, -a.second);
}
inline multiset<int>::iterator lung(const point &a)
{
return S3.find( -a.second + a.first - 1);
}
inline void inserez(int St, int Dr)
{
set<point>::iterator it;
point aux;
//exista (X, St-1)
it = S2.lower_bound( make_pair( -St+1, -INF) );
if (it != S2.end() && (*it).second == -St + 1){
aux = *it;
St = - (aux.first);
S1.erase( opus(aux) );
S2.erase( aux );
S3.erase( lung(opus(aux)) );
}
//exist (Dr+1, X)
it = S1.lower_bound( make_pair(Dr+1, -INF) );
if (it != S1.end() && (*it).first == Dr+1){
aux = *it;
Dr = aux.second;
S1.erase( aux );
S2.erase( opus(aux) );
S3.erase( lung(aux) );
}
S1.insert( make_pair(St, Dr) );
S2.insert( make_pair(-St, -Dr));
S3.insert( -Dr+St-1 );
}
inline void sterg(int St, int Dr)
{
set<point>::iterator it;
point aux;
it = S2.lower_bound( make_pair(-St, -INF) );
aux = *it;
S1.erase(opus(aux));
S2.erase(aux);
S3.erase(lung(opus(aux)));
//ramane la stanga
if (-aux.first < St)
inserez(-aux.first, St-1);
if (Dr < -aux.second)
inserez(Dr + 1, -aux.second);
}
int main()
{
freopen("hotel.in","r",stdin);
freopen("hotel.out","w",stdout);
scanf("%d %d",&N,&P);
inserez(1, N);
for (i = 1; i <= P; ++i){
scanf("%d",&Tip);
if (Tip == 1){
scanf("%d %d",&X, &Y);
sterg(X, X+Y-1);
}
if (Tip == 2){
scanf("%d %d",&X, &Y);
inserez(X, X+Y-1);
}
if (Tip == 3)
printf("%d\n", -(*S3.begin()));
}
return 0;
}