| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1311932 | settop | Shortcut (IOI16_shortcut) | C++20 | 0 ms | 0 KiB |
#include "railroad.h"
#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define fall(i,a,b) for(int i=a;i<=b;i++)
#define rfall(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
const ll inf=1e16;
typedef pair<ll,ll> pii;
vector<int> pai;
int find(int x){
return x==pai[x]?x:pai[x]=find(pai[x]);
}
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
int n = sz(s);
pai.resize(n);
fall(i,0,n-1) pai[i]=i;
set<pii> st;
fall(i,0,n-1) st.insert({s[i],i});
vector<int> ord;
fall(i,0,n-1) ord.pb(i);
sort(all(ord),[&](int a,int b){
if(t[a]!=t[b]) return t[a]>t[b];
return a<b;
});
bool foi=0;
for(auto u:ord){
auto it=st.lower_bound({t[u],-1});
if(it==st.end() && !foi){
foi=1;
continue;
}
else if(it==st.end()) return 1;
auto [x,i]=*it;
if(find(i)!=find(u)){
pai[find(i)]=find(u);
st.erase(it);
continue;
}
it++;
if(it==st.end() && !foi){
foi=1;
continue;
}
else if(it==st.end()) return 1;
pai[find((*it).second)]=find(u);
st.erase(it);
}
return 0;
}
