Pagini recente » Cod sursa (job #317365) | Cod sursa (job #2879777) | Cod sursa (job #476363) | Cod sursa (job #2545132) | Cod sursa (job #558487)
Cod sursa(job #558487)
#include <stdio.h>
#include <set>
using namespace std;
#define MAXN 100010
int L[MAXN];
struct classcomp {
bool operator() (const int& lhs, const int& rhs) const
{return L[lhs]>L[rhs];}
};
struct classcomp2 {
bool operator() (const int& lhs, const int& rhs) const
{return lhs>rhs;}
};
set<int,classcomp> S;
set<int,classcomp2> P;
int N,tip,i,poz,x,y,M;
int main()
{
freopen("hotel.in","r",stdin);
freopen("hotel.out","w",stdout);
scanf("%d %d",&N,&M);
L[1] = N;
P.insert(1); S.insert(1);
for (i=1; i<=M; ++i){
scanf("%d",&tip);
if (tip == 3){
if (S.size()!=0)
printf("%d\n", L[*S.begin()]);
else
printf("%d\n", 0);
}
if (tip == 2){
scanf("%d %d",&x,&y);
if (y==0) continue;
L[x] = y;
P.insert(x); S.insert(x);
y+=x-1;
if (L[y+1]){
S.erase(y+1);
P.erase(y+1);
S.erase(x); P.erase(x);
L[x] += L[y+1];
L[y+1] = 0;
S.insert(x);
P.insert(x);
}
if (P.upper_bound(x) == P.end()) continue;
poz = *P.upper_bound(x);
if (poz+L[poz] == x){
S.erase(poz);
P.erase(poz);
S.erase(x); P.erase(x);
L[poz]+=L[x];
L[x] = 0; x = poz;
S.insert(x); P.insert(x);
}
}
if (tip == 1){
scanf("%d %d",&x,&y);
if (y==0) continue;
poz = *P.lower_bound(x);
P.erase(poz); S.erase(poz);
L[x+y] = (poz+L[poz]-1) - (x+y-1);
if (L[x+y]!=0)
P.insert(x+y), S.insert(x+y);
L[poz] = x-poz;
if (L[poz]!=0)
P.insert(poz), S.insert(poz);
}
}
return 0;
}