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 + 5;
typedef long long ll;
ll A[MAXN], res, mn, mx;
ll findGap2(int T, int N){
MinMax(0, 1e18, &A[1], &A[N]);
for(int i=2, j=N-1; i<=j; ++i, --j) MinMax(A[i - 1] + 1, A[j + 1] - 1, &A[i], &A[j]);
for(int i=2; i<=N; i++) res = max(res, A[i] - A[i - 1]);
return res;
}
ll solve(ll lo, ll hi){
if(lo >= hi || hi - lo <= res) return 0;
unsigned long long x = (1LLU * lo + hi) / 2;
ll mid = (ll)(x), mn1 = -1, mx1 = -1, mn2 = -1, mx2 = -1;
if(lo < mid) MinMax(lo, mid, &mn1, &mx1);
if(mid + 1 < hi) MinMax(mid + 1, hi, &mn2, &mx2);
ll r = 0, r1 = 0, r2 = 0;
if(mx1 != -1 && mx2 != -1) r = mn2 - mx1;
if(mx2 != -1 && mx2 != mn2) r2 = solve(mn2, mx2);
if(mx1 != -1 && mx1 != mn1) r1 = solve(mn1, mx1);
res = max({res, r, r1, r2});
return res;
}
long long findGap(int T, int N){
if(T == 2){
MinMax(0, 1e18, &mn, &mx);
return solve(mn, mx);
}
return findGap2(T, N);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |