#include "shortcut.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N=1e6+5;
const ll X=1e15+1e9;
const ll INF=1e18;
int n,c;
ll a[N],d[N];
vector<int> ord1,ord2;
bool check(ll k){
ll l1=-INF,r1=INF; // x+y
ll l2=-INF,r2=INF; // x-y
ll mx1=-INF,mx2=-INF; // d[i]+a[i],d[i]-a[i]
auto ord=ord2;
for(auto i:ord1){
while(!ord.empty()&&d[i]+a[i]+d[ord.back()]-a[ord.back()]>k){
int j=ord.back();
ord.pop_back();
mx1=max(mx1,d[j]+a[j]);
mx2=max(mx2,d[j]-a[j]);
}
l1=max(l1,d[i]+a[i]+mx1-k+c);
r1=min(r1,-(d[i]-a[i])-mx2+k-c);
l2=max(l2,d[i]+a[i]+mx2-k+c);
r2=min(r2,-(d[i]-a[i])-mx1+k-c);
}
int pl1=n-1,pr1=n,pl2=-1,pr2=0;
for(int i=0;i<n;i++){
ll y=a[i];
while(pl1>=0&&a[pl1]+y>=l1)pl1--;
while(pl2+1<n&&a[pl2+1]-y<l2)pl2++;
while(pr2>0&&a[pr2-1]+y>r1)pr2--;
while(pr2<n&&a[pr2]-y<=r2)pr2++;
if(min(pr1,pr2)-max(pl1,pl2)>1)return true;
}
return false;
}
ll find_shortcut(int _n,vector<int> _l,vector<int> _d,int _c){
n=_n,c=_c;
for(int i=0;i+1<n;i++)a[i+1]=a[i]+_l[i];
for(int i=0;i<n;i++)d[i]=_d[i];
ord1.resize(n);
iota(ord1.begin(),ord1.end(),0);
ord2=ord1;
sort(ord1.begin(),ord1.end(),[&](int i,int j){return d[i]+a[i]<d[j]+a[j];});
sort(ord2.begin(),ord2.end(),[&](int i,int j){return d[i]-a[i]<d[j]-a[j];});
ll l=0LL,r=X;
while(l<r){
ll m=(l+r)/2;
if(check(m))r=m;
else l=m+1;
}
return l;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
344 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
440 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
348 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
344 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
440 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
348 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
344 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
440 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
348 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
344 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
440 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
348 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
344 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
440 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
348 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
344 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
440 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
348 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
344 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
440 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
348 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
344 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
440 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
348 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |