Submission #554366

#TimeUsernameProblemLanguageResultExecution timeMemory
554366KeshiGap (APIO16_gap)C++17
30 / 100
43 ms1880 KiB
//In the name of God
#include <bits/stdc++.h>
using namespace std;
#include "gap.h"


typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll maxn = 2e5 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e18 + 1000;

#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout);
#define pb push_back
#define Mp make_pair
#define F first
#define S second
#define Sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()

ll pw(ll a, ll b){
	ll c = 1;
	while(b){
		if(b & 1) c = c * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return c;
}

ll mn, mx, L, R, ans;
ll a[maxn];

ll solve(int n){
	L = 0;
	R = inf;
	for(int i = 0; i < (n + 1) / 2; i++){
		MinMax(L, R, &mn, &mx);
		a[i] = mn;
		a[n - i  - 1] = mx;
		L = mn + 1;
		R = mx - 1;
	}
	for(int i = 1; i < n; i++){
		ans = max(ans, a[i] - a[i - 1]);
	}
	return ans;
}

long long findGap(int T, int N){
	if(T == 1){
		return solve(N);
	}
	
	L = 0;
	R = inf;

	MinMax(L, R, &mn, &mx);
	ans = (R - L) / (N - 1);
	L = mn;
	R = mx;
	while(L < R){
		MinMax(L + 1, L + ans, &mn, &mx);
		if(mx != -1){
			L = mx;
			continue;
		}
		MinMax(L + 1, L + (ans + 1) * 2, &mn, &mx);
		while(mn == -1){
			ans = (ans + 1) * 2 + 1;
			MinMax(L + 1, L + (ans + 1) * 2, &mn, &mx);
		}
		ans = mn - L;
		L = mx;
	}

	return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...