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 "railroad.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
int n = (int) s.size();
set<pair<int,int>> lrset;
set<pair<int,int>> rlset;
for (int i = 0; i<n; i++){
lrset.insert({s[i],t[i]});
rlset.insert({t[i],s[i]});
}
while (lrset.size()>1){
/*cout<<'\n';
for (auto p : lrset){
cout<<p.first<<' '<<p.second<<'\n';
}*/
auto el = lrset.begin();
int firstl = el->first;
auto smallestrpair = rlset.lower_bound({firstl+1,-1});
if (smallestrpair!=rlset.begin()&&*prev(smallestrpair,1)==make_pair(el->second,el->first)){
smallestrpair = rlset.lower_bound({el->second,el->first-1});
}
if (smallestrpair==rlset.begin()){
el = next(el,1);
firstl = el->first;
smallestrpair = rlset.lower_bound({firstl+1,-1});
if (smallestrpair!=rlset.begin()&&*prev(smallestrpair,1)==make_pair(el->second,el->first)){
smallestrpair = rlset.lower_bound({el->second,el->first-1});
}
if (smallestrpair==rlset.begin()){
return 1;
}
}
smallestrpair = prev(smallestrpair,1);
//merge el with smallestrpair
int fpairl = el->first;
int fpairr = el->second;
int spairl = smallestrpair->second;
int spairr = smallestrpair->first;
lrset.erase({fpairl,fpairr});
rlset.erase({fpairr,fpairl});
lrset.erase({spairl,spairr});
rlset.erase({spairr,spairl});
lrset.insert({spairl,fpairr});
rlset.insert({fpairr,spairl});
}
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... |