Submission #369117

#TimeUsernameProblemLanguageResultExecution timeMemory
369117BartolMRoller Coaster Railroad (IOI16_railroad)C++17
0 / 100
303 ms35528 KiB
#include "railroad.h" #include <bits/stdc++.h> using namespace std; #define X first #define Y second #define mp make_pair #define pb push_back typedef long long ll; typedef pair <int, int> pii; typedef pair <int, pii> pip; typedef pair <pii, int> ppi; typedef pair <ll, ll> pll; const int INF=0x3f3f3f3f; const ll MAX=(ll)INF*INF; const int N=4e5+50; int n, maxi; vector <int> ls[N]; vector <int> saz; int desaz[N], val[N]; int P[N]; vector <pip> v; #define DEBUG 0 int name(int x) { if (x==P[x]) return x; P[x]=name(P[x]); return P[x]; } void mrg(int x, int y) { x=name(x); y=name(y); if (x==y) return; P[x]=y; } int sazmi(int x) { int ret=lower_bound(saz.begin(), saz.end(), x)-saz.begin(); desaz[ret]=x; return ret; } long long plan_roller_coaster(vector<int> s, vector<int> t) { s.pb(INF); t.pb(1); n=s.size(); ll sol=0; for (int i=0; i<n; ++i) saz.pb(s[i]), saz.pb(t[i]); sort(saz.begin(), saz.end()); saz.erase(unique(saz.begin(), saz.end()), saz.end()); maxi=saz.size(); for (int i=0; i<n; ++i) { s[i]=sazmi(s[i]); t[i]=sazmi(t[i]); ls[s[i]].pb(t[i]); val[s[i]]++, val[t[i]]--; } for (int i=0; i<maxi; ++i) { if (i) val[i]+=val[i-1]; // printf("i: %d, desaz[i]: %d, val: %d\n", i, desaz[i], val[i]); if (val[i]<0) ls[i].pb(i+1); if (val[i]>0) { sol+=(ll)val[i]*(desaz[i+1]-desaz[i]); ls[i+1].pb(i); } P[i]=i; } #if DEBUG printf("stabilizacija: %lld\n", sol); #endif // DEBUG return sol; for (int i=0; i<maxi; ++i) { for (int sus:ls[i]) mrg(i, sus); } } /* 4 1 7 4 3 5 8 6 6 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...