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 ll long long
ll mn,mx;
ll l,r,mid;
ll a[100005];
int h,t;
ll ans;
unsigned long long now,pre;
unsigned long long len;
long long findGap(int T, int N)
{
if (T==1) {
h=0,t=N+1;
l=0,r=1e18+1;
for (;;) {
MinMax(l,r,&mn,&mx);
a[++h]=mn,a[--t]=mx;
l=mn+1,r=mx-1;
if (h>=t-1) break;
}
for (int i=1;i<=N-1;i++) {
ll t=a[i+1]-a[i];
if (t>ans) ans=t;
}
} else {
MinMax(0,1e18+1,&mn,&mx);
now=mn;
len=1;
pre=mn;
ll top=mx;
ll d=1;
while (now+1<=top) {
MinMax(now+d,now+len,&mn,&mx);
if (mn==-1) {
now+=len;
d=1;
len*=2;
} else {
ans=max(ans,mn-(ll)pre);
d=now+len-mx+1;
now=mx;
pre=mx;
d=1;
}
}
}
return ans;
}
Compilation message (stderr)
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:35:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (now+1<=top) {
~~~~~^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |