#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
#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;
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;
}
*/
long long findGap(int T, int n){
ll ans = 1e18 + 5;
ans /= n;
ll a,b;
a = b = -1;
ll L = 0;
f(i,0,n-1){
ll l = 1,r = 1e18;
ll nxt = L;
while(l <= r){
ll mid = (l+r)/2;
MinMax(L,L+mid,&a,&b);
if(a == -1 || a == b){
l = mid + 1;
}
else{
nxt = min(nxt,b);
ans = min(ans,b - a);
r = mid - 1;
}
}
L = nxt;
}
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... |