Submission #373314

#TimeUsernameProblemLanguageResultExecution timeMemory
373314JasiekstrzRoller Coaster Railroad (IOI16_railroad)C++17
30 / 100
681 ms81388 KiB
#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; set<int> occ[N+10]; int id[N+10]; int wh[N+10]; 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,n}); bg.insert({INF,n}); 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(occ[it->id].find(x.id)!=occ[it->id].end()) it--; auto tmp=*it; sm.erase(it); if(occ[tmp.id].size()>occ[id[x.id]].size()) { int x_id=id[x.id]; for(auto v:occ[x_id]) { occ[tmp.id].insert(v); id[v]=tmp.id; } sm.erase({wh[x_id],x_id}); id[x.id]=tmp.id; wh[tmp.id]=wh[x_id]; sm.insert({wh[id[x.id]],id[x.id]}); } else { for(auto v:occ[tmp.id]) { occ[id[x.id]].insert(v); id[v]=id[x.id]; } } } auto it=sm.upper_bound({tab[i].s,INF}); if(it==sm.begin() || sm.empty()) { return 1; } if(tab[i].s>tab[i].t) { occ[i].insert(i); id[i]=i; wh[i]=tab[i].t; sm.insert({tab[i].t,i}); bg.insert({tab[i].s,i}); } else { auto tmp=*prev(it); sm.erase(prev(it)); occ[tmp.id].insert(i); id[i]=tmp.id; wh[tmp.id]=tab[i].t; sm.insert({tab[i].t,tmp.id}); } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...