# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1160436 | Doncho_Bonboncho | Gap (APIO16_gap) | C++20 | 0 ms | 0 KiB |
#include <algorithm>
#include <random>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include "gap.h"
#include <bits/stdc++.h>
using namespace std;
#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define out( x ) #x << " = " << x << " "
#define endl "\n"
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
typedef long long ll;
const ll mod = 1e9 +7;
const int MAX_N = 1e6 + 42;
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) {
cerr << out( s ) << out( t ) << endl;
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 a[MAX_N];
long long findGap(int subtask, int n){
if( subtask == 1 ){
int lInd = 1;
int rInd = n;
a[0] = -1;
a[n+1] = ll(1e18 + 1LL );
while( lInd <= rInd ){
MinMax( a[lInd-1] +1, a[rInd+1]-1, &a[lInd], &a[rInd] );
cerr << out( lInd ) << out( rInd ) << out( a[lInd] ) << out( a[rInd] ) << endl;
lInd ++;
rInd --;
}
for( int i=1 ; i <= n ; i++ ) cerr << a[i] << " ";
cerr << endl;
ll nas = 0;
for( int i=1 ; i < n ; i++ ){
cerr << out( i ) << out( a[i+1] - a[i] ) << endl;
chkmax( nas, ll( a[i+1] - a[i] ) );
}
cerr << out( nas ) << endl;
return nas;
}else{
// QJ MI KURA
return -1;
}
}
int main()
{
FILE *in = stdin, *out = stdout;
my_assert(2 == fscanf(in, "%d%d", &subtask_num, &N));
my_assert(1 <= subtask_num && subtask_num <= 2);
my_assert(2 <= N && N <= 100000);
for (int i=1;i<=N;i++) my_assert(1 == fscanf(in, "%lld", A+i));
for (int i=1;i<N;i++) my_assert(A[i] < A[i+1]);
fprintf(out, "%lld\n", findGap(subtask_num, N));
fprintf(out, "%lld\n", call_count);
}