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;
using ll = long long;
ll findGap(int t, int n) {
ll ans = 0;
if(t == 1) {
ll l = 0, r = 1e18;
ll a[n+1];
for(int i = 1; i <= n+1 >> 1; i++) {
MinMax(l, r, &l, &r);
a[i] = l;
a[n-i+1] = r;
++l, --r;
}
for(int i = 1; i < n; i++) ans = max(a[i+1] - a[i], ans);
} else {
ll l = 0, r = 1e18;
MinMax(l, r, &l, &r);
ll blk = (r-l+n-2) / (n-1);
assert(blk >= 1);
ll x = l, pre = 0;
while(x < r) {
ll tmpl, tmpr;
MinMax(x, x+blk-1, &tmpl, &tmpr);
if(tmpl == -1 && tmpr == -1) {
x += blk;
continue;
}
if(x != l) ans = max(tmpl - pre, ans);
pre = tmpr;
x += blk;
}
if(x == r) ans = max(x - pre, ans);
}
return ans;
}
Compilation message (stderr)
gap.cpp: In function 'll findGap(int, int)':
gap.cpp:11:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
for(int i = 1; i <= n+1 >> 1; i++) {
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |