省选专练APIO2016Gap

交互题坑爹啊

首先看30分

你一个一个比较一次可以比较两个

那么随便水过

剩下70分利用Batch均摊计算就可以

#include 
#include 
#include 
//#include "gap.h"
#define LL long long 
LL mx=1e18;
using namespace std;
static void my_assert(int k){ if (!k) exit(1); }

static int subtask_num, N;
static long long A[100001];
static long long call_count;

long long findGap(int, int);

void MinMax(long long s, long long t, long long *mn, long long *mx)
{
	int lo = 1, hi = N, left = N+1, right = 0;
	my_assert(s <= t && mn != NULL && mx != NULL);
	while (lo <= hi){
		int mid = (lo+hi)>>1;
		if (A[mid] >= s) hi = mid - 1, left = mid;
		else lo = mid + 1;
	}
	lo = 1, hi = N;
	while (lo <= hi){
		int mid = (lo+hi)>>1;
		if (A[mid] <= t) lo = mid + 1, right = mid;
		else hi = mid - 1;
	}
	if (left > right) *mn = *mx = -1;
	else{
		*mn = A[left];
		*mx = A[right];
	}
	if (subtask_num == 1) call_count++;
	else if (subtask_num == 2) call_count += right-left+2;
}
LL Max(LL A,LL B){
	if(A>B)
		return A;
	else 
		return B;
} 
LL findGap(int T,int N){
	if(T==1){
		LL lmin,lmax;
		LL ans=-1;
		MinMax((int)0,mx,&lmin,&lmax);
		if(N==2)
			return lmax-lmin;
		ans=-1;
		LL all=2;
		for(int i=2;i<=(N+1)/2;i++){
			LL minnow;
			LL minmax;
			MinMax(lmin+1,lmax-1,&minnow,&minmax);
			ans=Max(minnow-lmin,ans);
//			printf("%lld\n",ans);
			ans=Max(lmax-minmax,ans);
			all+=2;
			if(all==N){
				ans=Max(minmax-minnow,ans);
			}
			if(lmin==lmax||lmin==-1)
				break;
//			std::cout<

你可能感兴趣的:(APIO,2016)