#include <bits/stdc++.h>
using namespace std;
int n;
pair<int,int> a[200007];
int ind[200007],curr;
bool cmp(int x,int y){
return a[x].second>a[y].second;
}
int tree[4*200007],pos;
void build(int v,int l,int r){
if(l==r){
tree[v]=l;
}else{
int tt=(l+r)/2;
build(2*v,l,tt);
build(2*v+1,tt+1,r);
tree[v]=l;
}
}
void update(int v,int l,int r,int pos){
if(l==r){
tree[v]=n+1;
}else{
int tt=(l+r)/2;
if(pos<=tt)update(2*v,l,tt,pos);
else update(2*v+1,tt+1,r,pos);
tree[v]=min(tree[2*v],tree[2*v+1]);
}
}
int getmin(int v,int l,int r,int ll,int rr){
if(ll>rr)return n+1;
if(l==ll and r==rr){
return tree[v];
}else{
int tt=(l+r)/2;
return min( getmin(2*v,l,tt,ll,min(tt,rr)) , getmin(2*v+1,tt+1,r,max(tt+1,ll),rr) );
}
}
long long plan_roller_coaster(vector<int> s,vector<int> t){
n=s.size();
for(int i=1;i<=n;i++){
a[i]={s[i-1],t[i-1]};
ind[i]=i;
}
sort(a+1,a+n+1);
sort(ind+1,ind+n+1,cmp);
build(1,1,n);
for(int i=1;i<=n;i++){
curr=ind[i];
int l=0,r=n+1,tt;
while(l+1<r){
tt=(l+r)/2;
if(a[curr].second<=a[tt].first){
r=tt;
}else{
l=tt;
}
}
pos=getmin(1,1,n,r,n);
if(pos==curr)pos=getmin(1,1,n,pos+1,n);
if(pos==n+1)return 1;
update(1,1,n,pos);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 2 |
2 |
Correct |
0 ms |
212 KB |
n = 2 |
3 |
Correct |
0 ms |
212 KB |
n = 2 |
4 |
Correct |
1 ms |
212 KB |
n = 2 |
5 |
Correct |
0 ms |
212 KB |
n = 2 |
6 |
Incorrect |
1 ms |
212 KB |
answer is not correct: 1 instead of 523688153 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 2 |
2 |
Correct |
0 ms |
212 KB |
n = 2 |
3 |
Correct |
0 ms |
212 KB |
n = 2 |
4 |
Correct |
1 ms |
212 KB |
n = 2 |
5 |
Correct |
0 ms |
212 KB |
n = 2 |
6 |
Incorrect |
1 ms |
212 KB |
answer is not correct: 1 instead of 523688153 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
136 ms |
7756 KB |
n = 199999 |
2 |
Correct |
81 ms |
7768 KB |
n = 199991 |
3 |
Correct |
80 ms |
7768 KB |
n = 199993 |
4 |
Correct |
100 ms |
6624 KB |
n = 152076 |
5 |
Correct |
60 ms |
5580 KB |
n = 93249 |
6 |
Incorrect |
74 ms |
10560 KB |
answer is not correct: 1 instead of 0 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 2 |
2 |
Correct |
0 ms |
212 KB |
n = 2 |
3 |
Correct |
0 ms |
212 KB |
n = 2 |
4 |
Correct |
1 ms |
212 KB |
n = 2 |
5 |
Correct |
0 ms |
212 KB |
n = 2 |
6 |
Incorrect |
1 ms |
212 KB |
answer is not correct: 1 instead of 523688153 |
7 |
Halted |
0 ms |
0 KB |
- |