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;
using ll = long long;
const ll inf = 1e18;
ll a[100100];
int n;
ll ans = 1;
ll findGap(int T, int N) {
n = N;
if (T == 1) {
a[0] = -1, a[n + 1] = inf + 1;
for (int i = 1;i <= n / 2;i++) {
MinMax(a[i - 1] + 1, a[n - i + 2] - 1, &a[i], &a[n - i + 1]);
}
if (n & 1) {
ll _;
MinMax(a[n / 2] + 1, a[n / 2 + 2] - 1, &a[n / 2 + 1], &_);
}
for (int i = 1;i < n;i++) {
ans = max(ans, a[i + 1] - a[i]);
}
return ans;
}
ll mn, mx;
MinMax(0, inf, &mn, &mx);
ll now = mn;
while (now < mx) {
ll n1, n2;
MinMax(now + 1, now + ans, &n1, &n2);
if (n2 != -1) {
now = n2;
continue;
}
ll l = ans + 1, r = mx - now;
ll pnow = now + ans;
while (1) {
ll mid = (l + r) / 2;
ll nl, nr;
MinMax(pnow + 1, now + mid, &nl, &nr);
if (nl == -1) l = mid + 1, pnow = now + mid;
else {
ans = nl - now;
now = nl;
break;
}
}
//cout << ans << ' ';
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |