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 "gap.h"
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
typedef long long int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;
long long findGap(int T, int N)
{
lli c=0,arr[N],l=0,rem=0,g,r=1000000000000000000,l1=0,r1=N-1,ans1,ans2,m=0;
if(T==1)
{
for(;l1<=r1;)
{
MinMax(l,r,&ans1,&ans2);
arr[l1]=ans1;
l1++;
l=ans1+1;
arr[r1]=ans2;
r1--;
r=ans2-1;
}
for(lli i=0;i<N-1;++i)
m=max(m,arr[i+1]-arr[i]);
}
else
{
MinMax(l,r,&ans1,&ans2);
l=ans1+1;
r=ans2-1;
g=(r-l+1)/(N-1);
rem+=(r-l+1)%(N-1);
r1=g+l-1;
vector<ii> v;
v.pb(mp(ans1,ans1));
while(1)
{
MinMax(l,min(r1+min(1*1LL,rem),r),&ans1,&ans2);
if(r<=min(r1+min(1*1LL,rem),r))
break;
l=1+r1+min(1*1LL,rem);
r1=r1+min(1*1LL,rem)+g;
if(rem>0)
rem-=1;
if(ans1!=-1)
v.pb(mp(ans1,ans2));
}
v.pb(mp(r+1,r+1));
for(lli i=0;i<lli(v.size())-1;++i)
{
m=max(m,v[i+1].F-v[i].S);
}
}
return m;
}
Compilation message (stderr)
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:21:7: warning: unused variable 'c' [-Wunused-variable]
lli c=0,arr[N],l=0,rem=0,g,r=1000000000000000000,l1=0,r1=N-1,ans1,ans2,m=0;
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |