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"
#define ad push_back
#define lli long long int
using namespace std;
int n;
lli l, r;
long long findGap(int T, int N)
{
n = N;
lli nl, nr;
MinMax(0, 1e18, &nl, &nr);
if(T == 1 || N <= 8)
{
vector <lli> a, b;
a.ad(nl), b.ad(nr);
for (int i = 0; i < (n - 1) / 2; i++)
{
MinMax(nl + 1, nr - 1, &nl, &nr);
a.ad(nl), b.ad(nr);
}
lli mx = 0;
reverse(b.begin(), b.end());
for(auto p : b) a.ad(p);
for (int i = 0; i < a.size() - 1; i++)
mx = max(mx, a[i + 1] - a[i]);
return mx;
}
lli ans = 1;
while(nl < nr - ans)
{
l = -1;
if(l == -1)
{
while(l == -1)
{
MinMax(nl + 1LL, nl + ans * 2, &l, &r);
if(l == -1) ans *= 2LL, ans++;
else ans = max(ans, l - nl), nl = r;
}
}
else ans = max(ans, l - nl), nl = r;
}
return ans;
}
Compilation message (stderr)
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:27:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for (int i = 0; i < a.size() - 1; i++)
| ~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |