This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "gap.h"
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn = 2*1e5+5, INF = 4e18+9;
long long findGap(int T, int n)
{
ll ans = 0;
if(T == 1){
ll l = 0, r = INF;
ll mn, mx;
vector<ll> a(n+1);
for(int i = 1; i <= (n+1)/2; i++){
MinMax(l, r, &mn, &mx);
a[i] = mn; a[n-i+1] = mx;
l = mn+1, r = mx-1;
}
for(int i = 2; i <= n; i++){
ans = max(ans, a[i]-a[i-1]);
}
}else{
ll l = 0, r = INF;
ll mn, mx;
vector<ll> a(n+1);
MinMax(l, r, &mn, &mx);
l = mn, r = mx;
ll d = (r-l)/n;
ll len = r-l+1;
while(l < r){
MinMax(l+1, l+1+d, &mn, &mx);
if(mn != -1){
l = mx;
continue;
}
MinMax(l+1, l+1+d*2, &mn, &mx);
ll t = mn;
while(t == -1){
d*=2;
MinMax(l+1, l+1+d*2, &mn, &mx);
t = mn;
}
d = max(d, t-l);
l = mx;
}
ans = d;
}
return ans;
}
Compilation message (stderr)
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:30:12: warning: unused variable 'len' [-Wunused-variable]
30 | ll len = r-l+1;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |