Submission #151657

#TimeUsernameProblemLanguageResultExecution timeMemory
151657qkxwsmShortcut (IOI16_shortcut)C++14
93 / 100
2058 ms24332 KiB
#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 2696969696969696969ll 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; int ind[MAXN]; ll fen[2][MAXN]; 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 = ind[i]; 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); 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); int idx = LB(arr + i + 1, arr + N, MP(lt, -LLINF)) - arr; if (i < idx && idx < N && arr[idx].fi <= rt) return true; } 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()); FOR(i, 0, N) { ind[i] = LB(ALL(pts), arr[i].fi - arr[i].se) - pts.begin(); } 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...