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;
long long findGap(int T, int N) {
if (T == 1) {
long long Min = -1, Max = 1e18l + 1;
vector<long long> front, back;
for (int i = 0; i < (N + 1) / 2; i++) {
MinMax(Min + 1, Max - 1, &Min, &Max);
if (Min != Max) {
front.push_back(Min);
}
back.push_back(Max);
}
reverse(back.begin(), back.end());
vector<long long> A;
for (auto v : front) {
A.push_back(v);
}
for (auto v : back) {
A.push_back(v);
}
long long gap = 0;
for (int i = 0; i < N - 1; i++) {
gap = max(gap, A[i + 1] - A[i]);
}
return gap;
} else {
long long Min, Max;
MinMax(0, 1e18, &Min, &Max);
priority_queue<tuple<long double, long long, long long>> Q;
Q.push({1, Min, Max});
long long maxConfirmed = (Max - Min + N - 2) / (N - 1);
uniform_real_distribution<long double> dist(0, 1);
mt19937 rng(chrono::steady_clock().now().time_since_epoch().count());
while (!Q.empty()) {
auto [p, l, r] = Q.top();
Q.pop();
if (r - l <= maxConfirmed) {
continue;
}
long long mid = l + (r - l) / 2;
long long Minl = -1, Maxl = -1, Minr = -1, Maxr = -1;
if (l <= mid && mid - l > maxConfirmed) {
MinMax(l, mid, &Minl, &Maxl);
if (Minl != -1) {
Q.push({(Maxl - Minl) * dist(rng), Minl, Maxl});
}
}
if (mid + 1 <= r && r - mid - 1 > maxConfirmed) {
MinMax(mid + 1, r, &Minr, &Maxr);
if (Minr != -1) {
Q.push({(Maxl - Minl) * dist(rng), Minr, Maxr});
}
}
if (Maxl != -1 && Minr != -1) {
maxConfirmed = max(maxConfirmed, Minr - Maxl);
}
}
return maxConfirmed;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |