Cod sursa(job #2815091)

Utilizator AndreidreiGresoiu Liviu-Andrei Andreidrei Data 9 decembrie 2021 07:01:05
Problema Hotel Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.3 kb
#include <bits/stdc++.h>
#define din cin
#define dout out
#define pi 3.14159265359
#define sw(x,y) x^=y,y^=x,x^=y
#define bmin(a,b)((a<b)?(a):(b))
#define bmax(a,b)((a>b)?(a):(b))
#define ll long long
#define forq(i,ii,n)for(i=ii;i<n;i++)
using namespace std;
ifstream in("hotel.in");
ofstream out("hotel.out");
class compare{public:constexpr inline bool operator()(const ll a,const ll b){return a>b;}};
compare hhh;
ll n,q,i,j,x,k,l,r;map<ll,ll,compare>a(hhh);map<ll,bool>b[2];bool y;auto z=a.begin(),mz=a.begin();auto zz=b[0].begin();
struct t{bool t;ll i,l;}e[6000000];
#define makeint(ii,kk,yy)e[++l].t=yy,e[l].i=ii,e[l].l=kk,a[ii]=l,b[yy][((kk)<<32ll)+l]=0
int main()
{
in>>n>>q;
b[0][n<<32]=0,a[1]=0,e[0].i=1,e[0].l=n;
while(q--)
{
    //cout<<a[1]<<a.size()<<"kaj\n";
    in>>j;
    if(j==3)
        zz=b[0].end(),--zz,out<<((zz->first)>>32)<<' '<<'\n';
        else
        {
            y=(j==1),in>>x>>k,r=k;
            z=a.lower_bound(x);i=z->second;//cout<<z->first<<' '<<i<<" found i\n",cout<<a[1]<<a.size()<<"kaj\n";
            b[!y].erase(((e[i].l<<32))+i);
            //cout<<((e[i].l<<32))+i<<' '<<((e[i].l<<32))+i-(n<<32)<<' '<<e[i].l<<' '<<z->second<<' '<<z->first<<' '<<"fz erased\n";
            mz=z,--mz;
            if(e[i].l==k&&z!=a.begin())
                b[y].erase(((e[(mz)->second].l)<<32)+(mz)->second),k+=e[(mz)->second].l,makeint(x,k,y),a.erase(mz)/*,cout<<"right\n"*/;
                else if(e[i].l>k)makeint(x+k,z->first+e[i].l-x-k,!y)/*,cout<<"noright\n"*/;
            mz=z=a.lower_bound(x),++mz;
            if(x==z->first&&mz!=a.end())
                {
                    if(k!=r)mz=z,--mz,b[e[mz->second].t].erase(((e[mz->second].l<<32))+mz->second),mz=z,++mz;
                    k+=e[(mz)->second].l,b[y].erase(((e[(mz)->second].l)<<32)+(mz)->second),makeint(e[(mz)->second].i,k,y),a.erase(z)/*,cout<<"left"*/;
                }
                else if(x!=z->first)makeint(z->first,x-z->first,!y)/*,cout<<"noleft"*/;
            if(r==k)makeint(x,k,y);
            //for(auto z=a.begin();z!=a.end();z++)i=z->second,cout<<z->first<<' '<<e[i].t<<'-'<<e[i].i<<'-'<<e[i].l<<'\n';
            //cout<<b[0].size()<<"SIZE\n";
            //for(auto zz=b[0].begin();zz!=b[0].end();zz++)cout<<(zz->first>>32)<<'-'<<(zz->first&INT_MAX)<<' ';cout<<'\n';
        }
}
}