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"
using namespace std;
typedef long long ll;
ll findGap1(int N) {
ll l = 1, r = N;
ll fl = LLONG_MIN, fr = LLONG_MAX;
ll arr[N+1];
while (l <= r) {
ll *q1 = new ll(0), *q2 = new ll(0);
MinMax(fl, fr, q1, q2);
arr[l++] = *q1;
arr[r--] = *q2;
fl = *q1+1;
fr = *q2-1;
}
ll ans = 0;
for (ll i = 1; i < N; i++) ans = max(ans, arr[i+1] - arr[i]);
return ans;
}
void query(ll s, ll t, ll &q1, ll &q2) {
ll *qr1 = new ll(0), *qr2 = new ll(0);
MinMax(s, t, qr1, qr2);
q1 = *qr1;
q2 = *qr2;
}
ll findGap2(int N) {
ll mi, mx;
query(LLONG_MIN, LLONG_MAX, mi, mx);
ll ans = (mx-mi+N-1)/N; // by pigeonhole
ll lst = mi;
while (lst < mx) {
ll q1, q2;
query(lst+1, lst+ans, q1, q2);
if (q1 == -1) {
ll cq1, cq2;
query(lst+1, mx-1, cq1, cq2);
if (cq1 == -1) {
ans = mx-lst;
lst = mx;
} else {
ans = cq1-lst;
lst = cq1;
}
} else {
lst = q2;
}
}
return ans;
}
ll findGap(int T, int N) {
return T == 1 ? findGap1(N) : findGap2(N);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |