Submission #838061

#TimeUsernameProblemLanguageResultExecution timeMemory
838061pavementShortcut (IOI16_shortcut)C++17
71 / 100
2044 ms45848 KiB
#include "shortcut.h" #include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define eb emplace_back using ll = long long; struct ds { set<pair<ll, ll> > S; void insert(ll x, ll y) { vector<set<pair<ll, ll> >::iterator> to_erase; // insert (x, y) auto it = S.lower_bound(mp(x, 0ll)); if (it != S.end() && it->second >= y) { return; } if (it == S.end() || it->first != x) { if (it == S.begin()) { S.emplace(x, y); return; } --it; } while (1) { if (it->second <= y) { to_erase.pb(it); } else { break; } if (it == S.begin()) { break; } --it; } for (auto it2 : to_erase) { S.erase(it2); } S.emplace(x, y); } ll query(ll k) { // max y over all x > k auto it = S.upper_bound(mp(k, (ll)1e18)); return it == S.end() ? -(ll)1e18 : it->second; } }; ll find_shortcut(int n, vector<int> l, vector<int> d, int c) { vector<ll> x(n, 0); for (int i = 0; i + 1 < n; i++) { x[i + 1] = x[i] + (ll)l[i]; } auto good = [&](ll k) { ll min_x = -(ll)1e18, max_x = (ll)1e18, min_y = -(ll)1e18, max_y = (ll)1e18; vector<tuple<ll, bool, ll, ll*, int> > case_1_events; for (int i = 0; i < n; i++) { case_1_events.eb(d[i] - x[i], 0, x[i] + d[i], nullptr, i); case_1_events.eb(k - d[i] - x[i], 1, -k + c + d[i] - x[i], &min_x, i); case_1_events.eb(k - d[i] - x[i], 1, -k + c + d[i] + x[i], &min_y, i); } sort(case_1_events.begin(), case_1_events.end(), [](const tuple<ll, bool, ll, ll*, int> &lhs, const tuple<ll, bool, ll, ll*, int> &rhs) { auto lp = mp(get<0>(lhs), get<1>(lhs)), rp = mp(get<0>(rhs), get<1>(rhs)); return lp > rp; }); pair<ll, int> case_1_first_best = mp(-(ll)1e18, -1), case_1_second_best = mp(-(ll)1e18, -1); for (auto [_, type, offset, addr, idx] : case_1_events) { if (type == 0) { case_1_second_best = max(case_1_second_best, mp(offset, idx)); if (case_1_second_best > case_1_first_best) { swap(case_1_first_best, case_1_second_best); } } else { *addr = max(*addr, (case_1_first_best.second == idx ? case_1_second_best.first : case_1_first_best.first) + offset); } } { ds S; for (int j = 1; j < n; j++) { S.insert(d[j - 1] - x[j - 1], -(x[j - 1] - d[j - 1])); max_x = min(max_x, -S.query(k - d[j] - x[j]) + k - c - d[j] - x[j]); max_y = min(max_y, -S.query(k - d[j] - x[j]) + k - c - d[j] + x[j]); } } if (min_x <= max_x && min_y <= max_y) { set<ll> pos; for (int j = 1; j < n; j++) { pos.insert(x[j - 1]); ll lb = max(min_x + x[j], min_y - x[j]), rb = min(max_x + x[j], max_y - x[j]); auto it = pos.lower_bound(lb); if (it != pos.end() && *it <= rb) { return true; } } return false; } else { return false; } }; ll lo = 0, hi = (ll)1e16, ans = -1; while (lo <= hi) { ll mid = (lo + hi) / 2; if (good(mid)) { ans = mid; hi = mid - 1; } else { lo = mid + 1; } } return ans; }
#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...