#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)
break;
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;
}
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 |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 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 |
856 KB |
Output is correct |
17 |
Correct |
6 ms |
832 KB |
Output is correct |
18 |
Correct |
7 ms |
852 KB |
Output is correct |
19 |
Correct |
6 ms |
856 KB |
Output is correct |
20 |
Correct |
5 ms |
660 KB |
Output is correct |
21 |
Correct |
29 ms |
1880 KB |
Output is correct |
22 |
Correct |
27 ms |
1880 KB |
Output is correct |
23 |
Correct |
37 ms |
1872 KB |
Output is correct |
24 |
Correct |
26 ms |
1880 KB |
Output is correct |
25 |
Correct |
23 ms |
1876 KB |
Output is correct |
26 |
Correct |
30 ms |
1880 KB |
Output is correct |
27 |
Correct |
29 ms |
1880 KB |
Output is correct |
28 |
Correct |
26 ms |
1880 KB |
Output is correct |
29 |
Correct |
25 ms |
1876 KB |
Output is correct |
30 |
Correct |
27 ms |
1880 KB |
Output is correct |
31 |
Correct |
0 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 |
Incorrect |
0 ms |
344 KB |
Output isn't 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 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 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 |
6 ms |
628 KB |
Output is correct |
17 |
Correct |
4 ms |
600 KB |
Output is correct |
18 |
Correct |
4 ms |
540 KB |
Output is correct |
19 |
Correct |
4 ms |
600 KB |
Output is correct |
20 |
Incorrect |
3 ms |
600 KB |
Output isn't correct |
21 |
Correct |
26 ms |
1180 KB |
Output is correct |
22 |
Correct |
16 ms |
1112 KB |
Output is correct |
23 |
Correct |
16 ms |
1112 KB |
Output is correct |
24 |
Correct |
16 ms |
1112 KB |
Output is correct |
25 |
Correct |
32 ms |
1112 KB |
Output is correct |
26 |
Correct |
16 ms |
1112 KB |
Output is correct |
27 |
Correct |
17 ms |
1112 KB |
Output is correct |
28 |
Correct |
18 ms |
1112 KB |
Output is correct |
29 |
Correct |
16 ms |
1080 KB |
Output is correct |
30 |
Incorrect |
20 ms |
1108 KB |
Output isn't correct |
31 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |