#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
ll ans;
#include "gap.h"
/*
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;
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;
}
*/
void solve(ll l,ll r){
if(r - l <= ans){
return;
}
ll mid = (l+r)/2;
ll a,b,c,d;
a = b = c = d = -1;
MinMax(l,mid,&a,&b);
MinMax(mid+1,r,&c,&d);
if(a != b){
solve(a,b);
}
if(c != d){
solve(c,d);
}
ans = max(ans,c - b);
}
long long findGap(int T, int n){
ans = 0;
ll a,b;
a = b = -1;
MinMax(0,(ll)1e18,&a,&b);
solve(a,b);
return ans;
}
/*
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>subtask_num>>N;
for (int i=1;i<=N;i++) cin>>A[i];
printf("%lld\n", findGap(subtask_num, N));
printf("%lld\n", call_count);
}
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |