#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 |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
7 ms |
808 KB |
Output is correct |
17 |
Correct |
6 ms |
856 KB |
Output is correct |
18 |
Correct |
9 ms |
880 KB |
Output is correct |
19 |
Correct |
6 ms |
856 KB |
Output is correct |
20 |
Correct |
5 ms |
856 KB |
Output is correct |
21 |
Correct |
26 ms |
1868 KB |
Output is correct |
22 |
Correct |
25 ms |
1880 KB |
Output is correct |
23 |
Correct |
26 ms |
1880 KB |
Output is correct |
24 |
Correct |
25 ms |
1880 KB |
Output is correct |
25 |
Correct |
31 ms |
1880 KB |
Output is correct |
26 |
Correct |
26 ms |
1880 KB |
Output is correct |
27 |
Correct |
27 ms |
1880 KB |
Output is correct |
28 |
Correct |
31 ms |
1912 KB |
Output is correct |
29 |
Correct |
39 ms |
1880 KB |
Output is correct |
30 |
Correct |
20 ms |
1880 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
356 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
5 ms |
600 KB |
Output is correct |
17 |
Correct |
7 ms |
600 KB |
Output is correct |
18 |
Correct |
4 ms |
600 KB |
Output is correct |
19 |
Correct |
4 ms |
600 KB |
Output is correct |
20 |
Correct |
3 ms |
600 KB |
Output is correct |
21 |
Correct |
16 ms |
1112 KB |
Output is correct |
22 |
Correct |
16 ms |
1112 KB |
Output is correct |
23 |
Correct |
18 ms |
1112 KB |
Output is correct |
24 |
Correct |
21 ms |
1112 KB |
Output is correct |
25 |
Correct |
36 ms |
1112 KB |
Output is correct |
26 |
Correct |
26 ms |
1028 KB |
Output is correct |
27 |
Correct |
17 ms |
1112 KB |
Output is correct |
28 |
Correct |
26 ms |
1112 KB |
Output is correct |
29 |
Correct |
16 ms |
1112 KB |
Output is correct |
30 |
Correct |
14 ms |
1112 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |