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 <bits/stdc++.h>
#include "gap.h"
using namespace std;
/*int nn;
long long a[200001];
void MinMax(long long l,long long r,long long *mn,long long *mx)
{
*mn=-1;
for(int i=1;i<=nn;i++)
if(a[i]>=l)
{
*mn=a[i];
break;
}
*mx=-1;
for(int i=nn;i>=1;i--)
if(a[i]<=r)
{
*mx=a[i];
break;
}
}*/
long long n;
long long solve(long long l,long long r,long long ll,long long rr)
{
if(l==-1||l>r)return 0;
//cout<<l<<" "<<r<<" "<<ll<<" "<<rr<<endl;
long long ans=0;
long long len=r-l+1;
long long s=sqrt(len);
long long b=len/n;
long long last=-1;
for(long long i=l;i<=r;i+=b)
{
long long j=min(i+b-1,r);
long long mn=0,mx=0;
//cout<<i<<" "<<j<<endl;
MinMax(i,j,&mn,&mx);
if(mn==-1)continue;
if(last!=-1)ans=max(ans,mn-last);
else if(ll!=-1)ans=max(ans,mn-ll);
last=mx;
ans=max(ans,solve(mn+1,mx-1,mn,mx));
}
if(last==-1)last=ll;
if(last!=-1&&rr!=-1)ans=max(ans,rr-last);
return ans;
}
long long findGap(int t,int N)
{
n=N;
return solve(1,1e18,-1,-1);
}
/*int main()
{
long long d=0;
int x;
cin>>x>>nn;
for(int i=1;i<=nn;i++)
{
cin>>a[i];
if(i!=1)d=max(d,a[i]-a[i-1]);
}
long long answer=findGap(1,nn);
cout<<d<<" "<<answer<<endl;
}*/
Compilation message (stderr)
gap.cpp: In function 'long long int solve(long long int, long long int, long long int, long long int)':
gap.cpp:34:15: warning: unused variable 's' [-Wunused-variable]
34 | long long s=sqrt(len);
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |