Submission #956185

#TimeUsernameProblemLanguageResultExecution timeMemory
956185thinknoexitGap (APIO16_gap)C++17
42.65 / 100
39 ms1988 KiB
#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;
				if (nr - nl <= ans) now = nr;
				else now = nl;
				break;
			}
		}
		//cout << ans << ' ';
	}
	return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...