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;
map<int,int> m;
const int maxn = 4e5 + 10;
vector<int> grafo[maxn];
bool mark[maxn];
void dfs(int u){
mark[u] = 1;
for(int v : grafo[u]){
if(mark[v]) continue;
dfs(v);
}
}
long long plan_roller_coaster(vector<int> s, vector<int> t) {
int n = (int)s.size();
vector<int> v;
for(int x : s) v.push_back(x);
for(int x : t) v.push_back(x);
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
int tt = 0;
for(int x : v) m[x] = ++tt;
vector<int> sum(tt+1, 0);
for(int i=0; i<n; i++){
int u = m[s[i]], v = m[t[i]];
if(u == v) continue;
grafo[u].push_back(v);
if(u < v){
++sum[u];
--sum[v];
}
else{
--sum[v];
++sum[u];
}
}
--sum[1];
bool ok = 0;
for(int i=0; i<tt; i++){
if(i) sum[i] += sum[i-1];
if(sum[i] > 0) ok = 1;
else if(sum[i] < 0) grafo[i].push_back(i+1);
}
dfs(m[s[0]]);
for(auto x : m) ok |= !mark[x.second];
return ok;
}
# | 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... |