Submission #432711

#TimeUsernameProblemLanguageResultExecution timeMemory
432711MarcoMeijerRoller Coaster Railroad (IOI16_railroad)C++14
0 / 100
293 ms29944 KiB
#include "railroad.h" #include <bits/stdc++.h> using namespace std; // macros typedef long long ll; typedef long double ld; typedef pair<int, int> ii; typedef pair<ll, ll> lll; typedef tuple<int, int, int> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<iii> viii; typedef vector<ll> vll; typedef vector<lll> vlll; #define REP(a,b,c) for(int a=int(b); a<int(c); a++) #define RE(a,c) REP(a,0,c) #define RE1(a,c) REP(a,1,c+1) #define REI(a,b,c) REP(a,b,c+1) #define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--) #define FOR(a,b) for(auto& a : b) #define all(a) a.begin(), a.end() #define INF 1e9 #define EPS 1e-9 #define pb push_back #define popb pop_back #define fi first #define se second #define sz size() mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N=(1<<18); ii seg[N*2]; int laz[N*2]; void buildSeg(int p=1, int l=0, int r=N-1) { laz[p] = 0; if(l == r) { seg[p] = {0,l}; return; } int m=(l+r)/2; buildSeg(p*2,l,m); buildSeg(p*2+1,m+1,r); seg[p] = min(seg[p*2], seg[p*2+1]); } void addSeg(int p, int v) { seg[p] = {seg[p].fi+v, seg[p].se}; } void push(int p) { addSeg(p*2,laz[p]); addSeg(p*2+1,laz[p]); laz[p] = 0; } void addSeg(int i, int j, int v, int p=1, int l=0, int r=N-1) { if(j < i) return; if(j < l || i > r) return; if(i <= l && j >= r) { addSeg(p,v); return; } push(p); int m=(l+r)/2; addSeg(i,j,v,p*2,l,m); addSeg(i,j,v,p*2+1,m+1,r); seg[p] = min(seg[p*2], seg[p*2+1]); } ll plan_roller_coaster(vi s, vi t) { s.pb(1e9); t.pb(1); int n = s.size(); // coördinate compression vi difx; RE(i,n) difx.pb(s[i]), difx.pb(t[i]); sort(all(difx)); buildSeg(); set<int> unused; RE(i,difx.size()-1) unused.insert(i); RE(i,n) { int mn = min(s[i],t[i]); int mx = max(s[i],t[i])-1; if(mx < mn) continue; while(true) { auto it = unused.lower_bound(mn); if(it == unused.end()) break; int x = *it; if(x > mx) break; unused.erase(x); } } if(!unused.empty()) return 2; RE(i,n) { if(s[i] < t[i]) { addSeg(s[i],t[i]-1,1); } else { addSeg(t[i],s[i]-1,-1); } } if(seg[0].fi < 0) return 1; 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...