#include <bits/stdc++.h>
#define pb push_back
#define int int64_t
#include "shortcut.h"
#ifdef DEBUGGING
#include "../debug.h"
#else
#define debug(x...) void(42)
#endif
using namespace std;
constexpr static int MXN = 1e6 + 5;
constexpr static int INF = 1e18;
int pf[MXN];
vector<int> d, l;
int c, n;
static inline int dist(int a, int b)
{
return pf[max(a, b)] - pf[min(a, b)];
}
bool check(int k)
{
int xl = -INF, xr = INF, yl = -INF, yr = INF;
for (int i = 0; i < n; i++)
{
for (int j = i+1; j < n; j++)
{
if (dist(i, j) + d[i] + d[j] > k)
{
xl = max(xl, pf[j] + pf[i] - k + c + d[i] + d[j]);
xr = min(xr, pf[j] + pf[i] + k - c - d[i] - d[j]);
yl = max(yl, pf[j] - pf[i] - k + c + d[i] + d[j]);
yr = min(yr, pf[j] - pf[i] + k - c - d[i] - d[j]);
}
}
}
if (xr < xl || yr < yl)
return false;
int xs = 1, xe = 1, ys = n-1, ye = n-1;
for (int i = 0; i < n; i++)
{
while (xs < n && pf[i] + pf[xs] < xl) xs++;
while (xe < n && pf[i] + pf[xe] <= xr) xe++;
xe--;
while (ys >= 0 && pf[ys] - pf[i] > yl) ys--;
ys++;
while (ye >= 0 && pf[ye] - pf[i] > yr) ye--;
if (min(xs, ys) <= max(xe, ye))
return true;
}
return false;
}
long long find_shortcut(int32_t _n, vector<int32_t> _l, vector<int32_t> _d, int32_t _c)
{
c = _c;
n = _n;
for (int i : _l)
l.pb(i);
for (int i : _d)
d.pb(i);
array<int, 3> v = {0, 0, 0};
for (int i : d)
{
v[0] = i;
sort(v.begin(), v.end());
}
for (int i = 1; i <= n; i++)
pf[i] = pf[i-1] + l[i-1];#include <bits/stdc++.h>
#define pb push_back
#define int int64_t
#include "shortcut.h"
#define DEBUGGING
#ifdef DEBUGGING
#include "../debug.h"
#else
#define debug(x...) void(42)
#endif
using namespace std;
constexpr static int MXN = 1e6 + 5;
constexpr static int INF = 1e18;
int pf[MXN];
vector<int> d, l;
int c, n;
static inline int dist(int a, int b)
{
return pf[max(a, b)] - pf[min(a, b)];
}
bool check(int k)
{
int xl = -INF, xr = INF, yl = -INF, yr = INF;
for (int i = 0; i < n; i++)
{
for (int j = i+1; j < n; j++)
{
if (dist(i, j) + d[i] + d[j] > k)
{
xl = max(xl, pf[j] + pf[i] - k + c + d[i] + d[j]);
xr = min(xr, pf[j] + pf[i] + k - c - d[i] - d[j]);
yl = max(yl, pf[j] - pf[i] - k + c + d[i] + d[j]);
yr = min(yr, pf[j] - pf[i] + k - c - d[i] - d[j]);
}
}
}
if (xr < xl || yr < yl)
return false;
int xs = 1, xe = 1, ys = n-1, ye = n-1;
for (int i = 0; i < n; i++)
{
while (xs < n && pf[i] + pf[xs] < xl) xs++;
while (xe < n && pf[i] + pf[xe] <= xr) xe++;
xe--;
while (ys >= 0 && pf[ys] - pf[i] > yl) ys--;
ys++;
while (ye >= 0 && pf[ye] - pf[i] > yr) ye--;
if (min(xs, ys) <= max(xe, ye))
return true;
}
return false;
}
long long find_shortcut(int32_t _n, vector<int32_t> _l, vector<int32_t> _d, int32_t _c)
{
c = _c;
n = _n;
for (int i : _l)
l.pb(i);
for (int i : _d)
d.pb(i);
array<int, 3> v = {0, 0, 0};
for (int i : d)
{
v[0] = i;
sort(v.begin(), v.end());
}
for (int i = 1; i <= n; i++)
pf[i] = pf[i-1] + l[i-1];
//int ll = v[1] + v[2] + c - 1, rr = INF;
int ll = 0, rr = INF;
while (rr - ll > 1)
{
int m = ll+rr>>1;
if (check(m))
rr = m;
else
ll = m;
}
return rr;
}
//int ll = v[1] + v[2] + c - 1, rr = INF;
int ll = 0, rr = INF;
while (rr - ll > 1)
{
int m = ll+rr>>1;
if (check(m))
rr = m;
else
ll = m;
}
return rr;
}
Compilation message
shortcut.cpp:73:28: error: stray '#' in program
73 | pf[i] = pf[i-1] + l[i-1];#include <bits/stdc++.h>
| ^
shortcut.cpp:80:10: fatal error: ../debug.h: No such file or directory
80 | #include "../debug.h"
| ^~~~~~~~~~~~
compilation terminated.