Submission #242198

#TimeUsernameProblemLanguageResultExecution timeMemory
242198jiahngGap (APIO16_gap)C++14
30 / 100
74 ms2028 KiB
#include "gap.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define INF (ll)1e18
#define maxn 100001

ll arr[maxn];
long long findGap(int T, int N)
{
	if (T == 1){
		ll curs = 0, curt = INF;
		FOR(i,0,(N+1)/2 - 1){
			MinMax(curs,curt,arr + i, arr + N - i - 1);
			curs = arr[i] + 1;
			curt = arr[N - i - 1] - 1;
		}
		ll ans = 0;
		FOR(i,0,N-2) ans = max(ans,arr[i+1] - arr[i]);
		
		return ans;
	}else{
		ll mn=0,mx=0;
		MinMax(0LL,INF,&mn,&mx);
		
		ll lb = (mx - mn - 1 + N) / (N - 1);
		ll cur = mn;
		//cout<<lb<<'\n';
		ll ans = lb;
		
		ll prev = mn;
		while (cur < mx){
			ll x,y;
			MinMax(cur,cur + lb,&x,&y);
			if (x == -1){
				cur = min(mx,cur+lb+1);
				continue;
			}
			//cout<<x<<' '<<prev<<'\n';
			ans = max(ans,x - prev);
			prev = y;
			
			cur += lb+1;
		}
		//cout<<mx<<' '<<prev<<'\n';
		ans = max(ans,mx - prev);
		return ans;
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...