#include "bits/stdc++.h"
#include "gap.h"
using namespace std;
using ll = long long;
long long findGap(int t, int n) {
if (t == 1) {
vector<ll> a(n);
int l = 0, r = n - 1;
ll lx = -1, rx = 1e18 + 1;
while (l <= r) {
ll mn, mx;
MinMax(lx, rx, &mn, &mx);
// cout << '\t' << lx << ' ' << rx << ' ' << mn << ' ' << mx << endl;
a[l++] = mn, a[r--] = mx;
lx = mn + 1, rx = mx - 1;
}
ll ans = 0;
for (int i = 1; i < n; i++) ans = max(ans, a[i] - a[i - 1]);
return ans;
}
ll start, end;
MinMax(0, 1e18, &start, &end);
ll avg = (end - start) / (n - 1);
ll last = start, r = min(end - 1, start + avg), ans = avg;
// cout << '\t' << start << ' ' << end << ' ' << avg << endl;
while (true) {
ll mn, mx;
if (last == end) break;
MinMax(last + 1, r, &mn, &mx);
// cout << '\t' << last << ' ' << r << ' ' << mn << ' ' << mx << endl;
if (mn == -1) {
r = min(end, r + ans);
continue;
}
ans = max(ans, mn - last);
last = mx, r = min(end, mx + ans);
}
ans = max(ans, end - last);
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |