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;
const int maxn = 1e5+10;
const long long maxv = 1e18;
typedef long long ll;
ll a[maxn];
long long findGap(int T, int N)
{
if (T == 1)
{
ll mn, mx;
MinMax(0, maxv, &mn, &mx);
int l = 1, r = N;
a[1] = mn, a[N] = mx;
while (true)
{
if (r-l <= 1) break;
MinMax(a[l]+1, a[r]-1, &mn, &mx);
a[++l] = mn, a[--r] = mx;
}
ll ans = 0;
for (int i = 1; i < N; i++)
ans = max(ans, a[i+1]-a[i]);
return ans;
}
ll s = 0, mn, mx, last;
ll ans = 0;
MinMax(0, maxv, &mn, &mx);
s = mn, last = mx;
while (true)
{
mn = mx = -1;
ll k;
for (ll i = 0; i <= 60 && s+(1LL<<i) <= 2*maxv; i++)
{
ll t = s+(1LL<<i);
MinMax(s+1, t, &mn, &mx);
if (mn != -1 && mx != -1)
{
k = i;
break;
}
}
MinMax(s+1, s+(1LL<<k), &mn, &mx);
ans = max(ans, mn-s);
s = mx;
if (s >= last) break;
}
return ans;
}
Compilation message (stderr)
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:50:6: warning: 'k' may be used uninitialized in this function [-Wmaybe-uninitialized]
ll k;
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |