| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 844819 | dutinmeow | Gap (APIO16_gap) | C++17 | 0 ms | 0 KiB | 
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>
template<typename T>
bool chmax(T &a, T b) { 
	if (a >= b)
		return false;
	a = b;
	return true;
}
long long findGap(int t, int n) {
	if (t == 1) {
		std::vector<long long> a;
		a.reserve(n);
		long long bl = 0, br = 1e18;
		for (int i = 0; i < (n + 1) / 2; i++) {
			long long al, ar;
			MinMax(bl, br, &al, &ar);
			a.push_back(al);
			a.push_back(ar);
			bl = al + 1, br = ar - 1;
		}
		if (a.size() > n)
			a.pop_back();
		std::sort(a.begin(), a.end());
		long long r = 0;
		for (int i = 1; i < n; i++)
			chmax(r, a[i] - a[i - 1]);
		return r;
	} else {
		long long bl, br;
		MinMax(1, 1e18, &bl, &br);
		long long s = (br - bl - 1) / (n - 1);
		long long lb, r = s;
		for (lb = l; lb + s < r; lb += s + 1) {
			long long nl, nr;
			MinMax(lb, lb + s, &nl, &nr);
			if (nl != -1 && nr != -1) {
				chmax(r, nl - l)
				l = nr;
			}
		} 
		long long nl, nr;
		MinMax(lb, r, &nl, &nr);
		if (nl != -1 && nr != -1) 
			chmax(r, nl - l);
		return r;
	}
}
