제출 #237883

#제출 시각아이디문제언어결과실행 시간메모리
237883EvirirGap (APIO16_gap)C++17
100 / 100
83 ms1984 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "gap.h"
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define F first
#define S second
#define INF ll(1e18)
#define MOD 998244353
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }

#define MAXN 100005

ll mn,mx;

ll findGap(int T, int n)
{
	if(T==1)
	{
		ll L=0,R=1e18;
		ll a[n];
		for(int i=0;i<(n+1)/2;i++){
			MinMax(L,R,&mn,&mx);
			a[i]=mn, a[n-1-i]=mx;
			L=mn+1, R=mx-1;
		}
		ll ans=0;
		forn(i,0,n-1) ans=max(ans, a[i+1]-a[i]);
		return ans;
	}
	
	else
	{
		ll L,R,ans=0;
		MinMax(0,1e18,&L,&R);
		ll len=(R-L)/(n-1);
		ll pre=L;
		for(ll i=L+1;i<=R;i+=len+1){
			MinMax(i,i+len,&mn,&mx);
			if(mn!=-1){
				ans=max(ans, mn-pre);
				pre=mx;
			}
		}
		return ans;
	}
	
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...