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>
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define V vector
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
long long findGap(int T, int N)
{
if(T == 1) {
int l = 1, r = N;
ll lb = 0, rb = 1e18;
V<ll> v(N + 1);
while(l <= r) {
ll mn, mx;
MinMax(lb, rb, &mn, &mx);
v[l] = mn, v[r] = mx;
l++, r--;
lb = mn+1, rb = mx-1;
}
ll ans = 0;
for(int i = 1; i < N; i++) ans = max(ans, v[i+1]-v[i]);
return ans;
} else {
ll ans = 0;
function<void(ll, ll)> go = [&](ll lb, ll rb) {
if(lb == rb) return;
ll mn1, mx1, mn2, mx2;
ll mb = (lb + rb) / 2;
MinMax(lb, mb, &mn1, &mx1);
MinMax(mb+1, rb, &mn2, &mx2);
if(mn2 != -1 && mx1 != -1)
ans = max(ans, mn2 - mx1);
if(mn1 != -1 && mn1 != mx1) go(lb, mb);
if(mn2 != -1 && mn2 != mx2) go(mb+1, rb);
};
go(0, 1e18);
return ans;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |