#include "railroad.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
const int MAXN = 200005;
const int inf=1000000500ll;
const long long oo =1000000000000000500ll;
const int MOD = (int)1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int> pi;
namespace ufds{
int p[MAXN];
int sz[MAXN];
int find(int x){
if(p[x]==x)return x;
else return p[x]=find(p[x]);
}
void merge(int x, int y){
x=find(x);y=find(y);
if(x==y)return;
if(sz[x]<sz[y])swap(sz[x],sz[y]);
sz[x]+=sz[y];
p[y]=x;
}
};
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
iota(ufds::p,ufds::p+MAXN,0);
fill(ufds::sz,ufds::sz+MAXN,1);
s.push_back(2e9);
t.push_back(1);
vector<int>points;
map<int,int> mp;
int n=s.size();
for(int i=0;i<n;i++){
points.push_back(s[i]);
points.push_back(t[i]);
}
sort(points.begin(),points.end());
points.resize(unique(points.begin(),points.end())-points.begin());
for(int i=0;i<(int)points.size();i++){
mp[points[i]]=i+1;
}
int m=points.size();
int sum[m+5];memset(sum,0,sizeof sum);
for(int i=0;i<n;i++){
ufds::merge(mp[s[i]],mp[t[i]]);
sum[mp[s[i]]]++;
sum[mp[t[i]]]--;
}
for(int i=1;i<m;i++){
sum[i]+=sum[i-1];
if(sum[i]>0)return 1;
if(sum[i]<0){
ufds::merge(i,i+1);
}
}
for(int i=1;i<m;i++){
if(ufds::find(i) != ufds::find(i+1)){
return 1;
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1884 KB |
n = 2 |
2 |
Correct |
1 ms |
1884 KB |
n = 2 |
3 |
Correct |
1 ms |
1884 KB |
n = 2 |
4 |
Correct |
1 ms |
1884 KB |
n = 2 |
5 |
Correct |
1 ms |
1880 KB |
n = 2 |
6 |
Incorrect |
1 ms |
1880 KB |
answer is not correct: 1 instead of 523688153 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1884 KB |
n = 2 |
2 |
Correct |
1 ms |
1884 KB |
n = 2 |
3 |
Correct |
1 ms |
1884 KB |
n = 2 |
4 |
Correct |
1 ms |
1884 KB |
n = 2 |
5 |
Correct |
1 ms |
1880 KB |
n = 2 |
6 |
Incorrect |
1 ms |
1880 KB |
answer is not correct: 1 instead of 523688153 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
166 ms |
54452 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1884 KB |
n = 2 |
2 |
Correct |
1 ms |
1884 KB |
n = 2 |
3 |
Correct |
1 ms |
1884 KB |
n = 2 |
4 |
Correct |
1 ms |
1884 KB |
n = 2 |
5 |
Correct |
1 ms |
1880 KB |
n = 2 |
6 |
Incorrect |
1 ms |
1880 KB |
answer is not correct: 1 instead of 523688153 |
7 |
Halted |
0 ms |
0 KB |
- |