This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include "railroad.h"
using namespace std;
struct Road
{
int s,t;
inline bool operator<(const Road &oth)
{
if(t==oth.t)
return s<oth.s;
return t<oth.t;
}
};
struct Small
{
int t,id;
inline bool operator<(const Small &oth) const
{
if(t==oth.t)
return id<oth.id;
return t<oth.t;
}
};
struct Big
{
int s,id;
inline bool operator<(const Big &oth) const
{
if(s==oth.s)
return id<oth.id;
return s<oth.s;
}
};
const int N=2e5;
const int INF=1e9+7;
Road tab[N+10];
set<Small> sm;
set<Big> bg;
long long plan_roller_coaster(vector<int> s,vector<int> t)
{
int n=s.size();
for(int i=0;i<n;i++)
tab[i]={s[i],t[i]};
sort(tab,tab+n);
sm.insert({0,0});
bg.insert({INF,0});
for(int i=0;i<n;i++)
{
while(!bg.empty() && (bg.begin()->s)<tab[i].t)
{
auto x=*bg.begin();
bg.erase(x);
auto it=prev(sm.end());
if((it->id)==x.id)
it--;
sm.erase(it);
}
auto it=sm.upper_bound({tab[i].s,-1});
if(it==sm.begin() || sm.empty())
return 1;
if(tab[i].s>tab[i].t)
{
sm.insert({tab[i].s,i});
bg.insert({tab[i].t,i});
}
else
{
sm.erase(prev(it));
sm.insert({tab[i].t,i});
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |