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 "shortcut.h"
using namespace std;
template<class T, class U>
void ckmin(T &a, U b)
{
if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
if (a < b) a = b;
}
#define y1 qwertyuiop
#define y2 asdfghjkl
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define SZ(x) ((int) ((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define MAXN 1000013
#define INF 1000000007
#define LLINF 2696969696969696969
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
int N;
ll D;
pll arr[MAXN];
vl pts;
ll fen[2][MAXN];
set<ll> vals;
bool check(ll s)
{
pll x = {-LLINF, LLINF}, y = {-LLINF, LLINF};
FOR(i, 0, SZ(pts) + 1)
{
fen[0][i] = LLINF; fen[1][i] = -LLINF;
}
FOR(i, 0, N)
{
ll c = arr[i].fi, d = arr[i].se;
int idx = LB(ALL(pts), c + d - s) - pts.begin() - 1;
ll mx = -LLINF, mn = LLINF;
for (int e = idx + 1; e; e -= e & (-e))
{
ckmax(mx, fen[1][e]);
ckmin(mn, fen[0][e]);
}
ckmax(x.fi, mx + c + d); ckmin(x.se, mn + c - d);
ckmax(y.fi, mx - c + d); ckmin(y.se, mn - c - d);
idx = LB(ALL(pts), c - d) - pts.begin();
for (int e = idx + 1; e <= SZ(pts); e += e & (-e))
{
ckmax(fen[1][e], c + d);
ckmin(fen[0][e], c - d);
}
}
x.fi += (D - s); x.se += (s - D);
y.fi += (D - s); y.se += (s - D);
vals.clear();
FORD(i, N, 0)
{
ll m = arr[i].fi;
ll lt = max(x.fi - m, m - y.se), rt = min(x.se - m, m - y.fi);
auto it = vals.LB(lt);
if (it != vals.end() && *it <= rt) return true;
vals.insert(m);
}
return false;
}
ll find_shortcut(int n, vi l, vi d, int vs)
{
N = n; D = vs;
l.insert(l.begin(), 0);
FOR(i, 0, N)
{
arr[i].fi = l[i];
arr[i].se = d[i];
}
FOR(i, 1, N)
{
arr[i].fi += arr[i - 1].fi;
}
FOR(i, 0, N)
{
pts.PB(arr[i].fi - arr[i].se);
}
sort(ALL(pts));
pts.erase(unique(ALL(pts)), pts.end());
ll lo = 0, hi = (1ll << 50);
while(hi > lo)
{
ll mid = (hi + lo) >> 1;
if (check(mid)) hi = mid;
else lo = mid + 1;
}
return lo;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |