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 "shortcut.h"
#include <iostream>
using namespace std;
const int nmax=1000*1000+5;
const long long inf=1LL*1e18;
int d[nmax];
long long x[nmax],y[nmax];
int i,n;
long long C;
bool check(long long k)
{
long long mxsum=-inf,mndif=inf;
long long suml=-inf,sumr=inf,difl=-inf,difr=inf;
long long sum,dif;
int p=1,u=0;
for(i=1;i<=n;i++)
{
while(p<=u&&x[i]-x[d[p]]+y[i]+y[d[p]]>k)
{
sum=x[d[p]]+y[d[p]];dif=x[d[p]]-y[d[p]];
if(sum>mxsum) mxsum=sum;
if(dif<mndif) mndif=dif;
p++;
}
if(mxsum!=-inf)
{
suml=max(suml,-k+C+mxsum+x[i]+y[i]);
sumr=min(sumr,k-C+mndif+x[i]-y[i]);
difl=max(difl,-k+C-mndif+x[i]+y[i]);
difr=min(difr,k-C-mxsum+x[i]-y[i]);
}
while(p<=u&&x[i]-y[i]<x[d[u]]-y[d[u]])
u--;
d[++u]=i;
}
if(suml>sumr||difl>difr) return 0;
int p1=1,p2=n;
int poz;
for(i=1;i<=n;i++)
{
while(p1<=n&&x[p1]-x[i]<difl)
p1++;
while(p2>=1&&x[p2]+x[i]>=suml)
p2--;
poz=max(i+1,max(p1,p2+1));
if(poz<=n&&x[poz]+x[i]>=suml&&x[poz]+x[i]<=sumr&&x[poz]-x[i]>=difl&&x[poz]-x[i]<=difr)
return 1;
}
return 0;
}
long long find_shortcut(int N, std::vector<int> l, std::vector<int> d, int c)
{
C=c;n=N;
for(i=0;i<n-1;i++)
x[i+2]=x[i+1]+l[i];
for(i=0;i<n;i++)
y[i+1]=d[i];
long long ans=0;
for(long long p=50;p>=0;p--)
ans+=(1LL<<p);
for(long long p=50;p>=0;p--)
if(check(ans-(1LL<<p)))
ans-=(1LL<<p);
return ans;
}
# | 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... |
# | 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... |