제출 #45258

#제출 시각아이디문제언어결과실행 시간메모리
45258nibnalinGap (APIO16_gap)C++17
46.91 / 100
116 ms2276 KiB
#include <iostream>
#include <cstdio>
#include <vector>
#include "gap.h"
using namespace std;

typedef long long int lli;

const lli maxn = int(1e5)+5, inf = lli(1e18)+1;

lli ans = 0, A[maxn];

void sub1(lli n)
{
	pair<lli, lli> range = {0, inf};
	lli L = 0, R = n-1;
	while(L <= R)
	{
		MinMax(range.first, range.second, &A[L], &A[R]);
		range.first = A[L]+1, range.second = A[R]-1;
		L++, R--;
	}
	for(lli i = 1;i < n;i++) ans = max(ans, A[i]-A[i-1]);
}

void qry(lli L, lli R)
{
	//cout << L << " " << R << "\n";
	if(R-L < ans) return;
	pair<lli, lli> left = {L, (L+R)/2}, right = {(L+R)/2+1, R};
	pair<lli, lli> leftst, rightst;
	MinMax(left.first, left.second, &leftst.first, &leftst.second), MinMax(right.first, right.second, &rightst.first, &rightst.second);
	ans = max(ans, rightst.first-leftst.second);
	if(leftst.first != leftst.second && leftst.first != -1) qry(leftst.first, leftst.second);
	if(rightst.first != rightst.second && rightst.first != -1) qry(rightst.first, rightst.second);
}

void sub2(lli n)
{
	qry(0, inf);
}

lli findGap(int t, int n)
{
	if(t == 1) sub1(n);
	else sub2(n);
	return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...