#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 = 600005;
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;
struct fenw {
int fw[MAXN];
void update(int x, int nval){
for(;x<MAXN;x+=x&-x)fw[x]+=nval;
}
void update(int x, int y, int nval){
update(x,nval);
update(y+1,-nval);
}
int point(int x){
int res=0;
for(;x;x-=x&-x)res+=fw[x];
return res;
}
}fw,fw2;
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(1e9);
t.push_back(1);
vector<int>points;
map<int,int> mp;
int n=s.size();
for(int i=0;i<n;i++){
if(s[i]==t[i]){
points.push_back(s[i]);
} else if(s[i]<t[i]){
points.push_back(s[i]);
points.push_back(t[i]);
points.push_back(t[i]-1);
} else if(s[i]>t[i]){
points.push_back(s[i]-1);
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;
}
for(int i=0;i<n;i++){
ufds::merge(mp[s[i]],mp[t[i]]);
fw.update(mp[s[i]],mp[t[i]-1],1);
if(s[i]<t[i]){
fw2.update(mp[s[i]],mp[t[i-1]],1);
} else{
fw2.update(mp[t[i]],mp[s[i]-1],1);
}
/*
if(s[i]<t[i]){
fw.update(mp[s[i]],mp[t[i]-1],1);
} else {
fw.update(mp[t[i]],mp[s[i]-1],-1);
}*/
}
int m=points.size();
for(int i=1;i<=m;i++){
int r=fw.point(i);
if(r>0)return 1;
/*
if(fw2.point(i)){
ufds::merge(i,i+1);
}*/
}
/*
for(int i=1;i<=m;i++){
if(ufds::find(i) != ufds::find(1)){
return 1;
}
}*/
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8796 KB |
n = 2 |
2 |
Correct |
1 ms |
8796 KB |
n = 2 |
3 |
Correct |
1 ms |
8796 KB |
n = 2 |
4 |
Correct |
1 ms |
8796 KB |
n = 2 |
5 |
Correct |
1 ms |
8796 KB |
n = 2 |
6 |
Incorrect |
2 ms |
8796 KB |
answer is not correct: 1 instead of 523688153 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8796 KB |
n = 2 |
2 |
Correct |
1 ms |
8796 KB |
n = 2 |
3 |
Correct |
1 ms |
8796 KB |
n = 2 |
4 |
Correct |
1 ms |
8796 KB |
n = 2 |
5 |
Correct |
1 ms |
8796 KB |
n = 2 |
6 |
Incorrect |
2 ms |
8796 KB |
answer is not correct: 1 instead of 523688153 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
665 ms |
53436 KB |
n = 199999 |
2 |
Correct |
634 ms |
49636 KB |
n = 199991 |
3 |
Correct |
652 ms |
44432 KB |
n = 199993 |
4 |
Correct |
490 ms |
40264 KB |
n = 152076 |
5 |
Correct |
215 ms |
27304 KB |
n = 93249 |
6 |
Correct |
546 ms |
40032 KB |
n = 199910 |
7 |
Correct |
654 ms |
48940 KB |
n = 199999 |
8 |
Correct |
515 ms |
40472 KB |
n = 199997 |
9 |
Correct |
562 ms |
42996 KB |
n = 171294 |
10 |
Correct |
417 ms |
37956 KB |
n = 140872 |
11 |
Incorrect |
536 ms |
43612 KB |
answer is not correct: 0 instead of 1 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8796 KB |
n = 2 |
2 |
Correct |
1 ms |
8796 KB |
n = 2 |
3 |
Correct |
1 ms |
8796 KB |
n = 2 |
4 |
Correct |
1 ms |
8796 KB |
n = 2 |
5 |
Correct |
1 ms |
8796 KB |
n = 2 |
6 |
Incorrect |
2 ms |
8796 KB |
answer is not correct: 1 instead of 523688153 |
7 |
Halted |
0 ms |
0 KB |
- |