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 <bits/stdc++.h>
#include "gap.h"
using namespace std;
using ll = long long;
ll inf = (ll)1e9 * (ll)1e9;
ll findGap(int t, int n)
{
if (t == 1)
{
vector<ll> a(n);
ll l = 0,r = inf;
for (int i = 0; i < n / 2 + n % 2; i++)
{
ll mn,mx;
MinMax(l,r,&mn,&mx);
a[i] = mn;
a[n - 1 - i] = mx;
l = mn + 1,r = mx - 1;
}
ll md = 0;
for (int i = 1; i < n; i++)
md = max(md,a[i] - a[i - 1]);
return md;
}
else
{
ll l = 0,r = inf;
MinMax(l,r,&l,&r);
ll g = (r - l) / (n - 1);
ll u = l;
ll p = l + 1;
while (true)
{
ll st = p,dr = p + g - 1;
if (dr > r)
dr = r;
ll mn,mx;
MinMax(st,dr,&mn,&mx);
if (mn != -1)
g = max(g,mn - u),u = mx,p = mx + 1;
else
p = dr + 1;
if (dr == r)
break;
}
return g;
}
}
/**
Hai sa dau un query [0 inf] ca sa determin L si R, primul si ultimul numar
Stiu ca G >= (R - L) / (N - 1) rounded up
Intreb [L + 1, L + G] -> daca nu e nimic, ok, continui, altfel stiu ca ma uit doar de la ultimul din interval incolo (restul sunt gapuri mici)
M o sa fie 3N + const (nush daca pozitiva sau negativa, de vazut)
**/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |