#include <bits/stdc++.h>
using namespace std;
const int N = 1000001;
long long fenw[N][2], sum[N], diff[N], x[N];
int sum_order[N], diff_order[N], n;
array<long long, 2> query(int a) {
long long min_ans = LLONG_MAX, max_ans = LLONG_MIN;
for ( ; a > 0; a -= a & -a) {
min_ans = min(min_ans, fenw[a][0]);
max_ans = max(max_ans, fenw[a][1]);
}
return {min_ans, max_ans};
}
void update(int a, long long x, long long y) {
for ( ; a <= n; a += a & -a) {
fenw[a][0] = min(fenw[a][0], x);
fenw[a][1] = max(fenw[a][1], y);
}
}
long long find_shortcut(int n, vector<int> l, vector<int> d, int c) {
::n = n;
for (int i = 0; i < n - 1; ++i) {
x[i + 1] = x[i] + l[i];
}
for (int i = 0; i < n; ++i) {
sum[i] = x[i] + d[i];
diff[i] = x[i] - d[i];
}
iota(sum_order, sum_order + n, 0);
sort(sum_order, sum_order + n, [&](int a, int b) {
return sum[a] < sum[b];
});
iota(diff_order, diff_order + n, 0);
sort(diff_order, diff_order + n, [&](int a, int b) {
return diff[a] < diff[b];
});
long long low = 0, high = sum[sum_order[n - 1]] - diff[diff_order[0]];
while (low < high) {
long long mid = (low + high) / 2;
long long min_sum = LLONG_MIN, max_sum = LLONG_MAX;
long long min_diff = LLONG_MIN, max_diff = LLONG_MAX;
for (int i = 0; i < n; ++i) {
fenw[i][0] = LLONG_MAX;
fenw[i][1] = LLONG_MIN;
}
for (int i = 0, j = 0; j < n; ++j) {
while (i < n && sum[sum_order[j]] - diff[diff_order[i]] > mid) {
update(diff_order[i] + 1, diff[diff_order[i]], sum[diff_order[i]]);
++i;
}
auto [min_i, max_i] = query(sum_order[j]);
if (min_i < LLONG_MAX) {
min_sum = max(min_sum, -mid + c + sum[sum_order[j]] + max_i);
max_sum = min(max_sum, mid - c + diff[sum_order[j]] + min_i);
min_diff = max(min_diff, -mid + c + sum[sum_order[j]] - min_i);
max_diff = min(max_diff, mid - c + diff[sum_order[j]] - max_i);
}
}
bool ok = false;
int l1 = n - 1, l2 = 0, r1 = n - 1, r2 = 0;
for (int i = 0; i < n; ++i) {
while (l1 >= 0 && x[i] + x[l1] >= min_sum) {
--l1;
}
while (r1 >= 0 && x[i] + x[r1] > max_sum) {
--r1;
}
while (l2 < n && x[i] - x[l2] > max_sum) {
++l2;
}
while (r2 < n && x[i] - x[r2] >= min_sum) {
++r2;
}
ok |= max(l1 + 1, l2) < min(r1 + 1, r2);
}
if (ok) {
high = mid;
} else {
low = mid + 1;
}
}
return low;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
n = 4, incorrect answer: jury 80 vs contestant 90 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
n = 4, incorrect answer: jury 80 vs contestant 90 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
n = 4, incorrect answer: jury 80 vs contestant 90 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
n = 4, incorrect answer: jury 80 vs contestant 90 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
n = 4, incorrect answer: jury 80 vs contestant 90 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
n = 4, incorrect answer: jury 80 vs contestant 90 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
n = 4, incorrect answer: jury 80 vs contestant 90 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
n = 4, incorrect answer: jury 80 vs contestant 90 |
2 |
Halted |
0 ms |
0 KB |
- |