Submission #68205

#TimeUsernameProblemLanguageResultExecution timeMemory
68205gusfringGap (APIO16_gap)C++14
43.80 / 100
167 ms2240 KiB
#include <bits/stdc++.h>
#include "gap.h"

using namespace std;

const int MAXN = 1e5 + 5;
typedef long long ll;

long long A[MAXN], res;
 
long long 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 mn, mx;
 
ll solve(ll lo, ll hi){
	if(lo >= hi) 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 res = 0, r1 = 0, r2 = 0;
	if(mx1 != -1 && mx2 != -1) res = mn2 - mx1;
	if(mx2 != -1 && mx2 != mn2) r2 = solve(mn2, mx2);
	if(mx1 != -1 && mx1 != mn1) r1 = solve(mn1, mx1);
	return max({res, r1, r2});
}
 
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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...