Pagini recente » Cod sursa (job #806170) | Cod sursa (job #2185304) | Cod sursa (job #2135401) | Cod sursa (job #2871134) | Cod sursa (job #2309256)
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#define y first
#define x second
using namespace std;
int n,p,s,d,o,sa,da;
set< pair<int,int> > si;
multiset<int> sl;
vector< pair<int,int> > ids;
void adauga(int st,int dr){
si.insert(make_pair(dr,st));
sl.insert(dr-st+1);
}
void adauga_sters(int st,int dr){
ids.push_back(make_pair(st,dr));
}
void sterge(){
for(auto i:ids)
si.erase(make_pair(i.y,i.x)),
sl.erase(i.y-i.x+1);
}
void afiseaza(int op,int st,int dr){
cout<<"\\/----------------------------------\\/\n";
if(op==1)cout<<"eliminare ";
if(op==2)cout<<"eliberare ";
if(op==3)cout<<"afisare\n";
else{
cout<<st<<" "<<dr<<":\n";
for(auto i:si)
cout<<i.x<<" "<<i.y<<"\n\n";
cout<<"\n---\n";
for(auto i:sl)
cout<<i<<" ";
cout<<"\n";
}
cout<<"/\\----------------------------------/\\\n\n\n\n\n";
}
int main()
{
ifstream f ("hotel.in");
ofstream g ("hotel.out");
f>>n>>p;
adauga(1,n);
//afiseaza(2,1,n);
while(p--){
f>>o;
if(o==1){
f>>s>>d; d=s+d-1;
set< pair<int,int> >::iterator it;
it=si.lower_bound(make_pair(d,0));
sa=(*it).x; da=(*it).y;
si.erase(make_pair(da,sa)); sl.erase(da-sa+1);
if(sa!=s)adauga(sa,s-1);
if(da!=d)adauga(d+1,da);
} else if(o==2){
f>>s>>d; d=s+d-1; ids.clear();
set< pair<int,int> >::iterator it;
it=si.lower_bound(make_pair(d,0));
sa=s;da=d;
if(it!=si.end())
if((*it).y>=da&&(*it).x==da+1){
da=(*it).y;
adauga_sters((*it).y,(*it).x);
}
if(it!=si.begin()){
//cout<<"---> "<<(*it).y<<" <---\n";
it--;
//cout<<"---> "<<(*it).y<<" <---\n";
if((*it).y<=sa&&(*it).y==sa-1){
//cout<<"ok\n";
sa=(*it).x;
adauga_sters((*it).y,(*it).x);
}
}
sterge();
adauga(sa,da);
} else {
if(sl.size())
g<<(*sl.rbegin())<<'\n';
else g<<"0\n";
}
//afiseaza(o,s,d);
}
f.close ();
g.close ();
return 0;
}