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 <bits/stdc++.h>
using namespace std;
vector<long long> a;
void findarr (long long low, long long high) {
long long mnl, mxl, mnr, mxr;
int mid = (low+high)/2;
MinMax(low, low, &mnl, &mxl);
MinMax(mid+1, high, &mnr, &mxr);
if (mnl != -1) {
a.push_back(mnl);
a.push_back(mxl);
}
if (mnr != -1) {
a.push_back(mnr);
a.push_back(mxr);
}
if (mnl != mxl) findarr(mnl+1, mxl-1);
if (mnr != mxr) findarr(mnr+1, mxr-1);
}
long long findGap(int T, int N) {
long long ans = 0;
if (T == 1) {
a.resize(N);
long long mn, mx;
long long l = 0, r = 1e18;
int indl = 0, indr = N-1;
while (indl <= indr) {
MinMax(l, r, &mn, &mx);
if (mn != -1) {
a[indl++] = mn;
a[indr--] = mx;
}
l = mn+1; r = mx-1;
}
for (int i = 1; i < N; i++) {
ans = max(ans, a[i]-a[i-1]);
}
}
else {
findarr(0, 1e18);
sort(a.begin(), a.end());
for (int i = 1; i < N; i++) {
ans = max(ans, a[i]-a[i-1]);
}
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |