Submission #819951

#TimeUsernameProblemLanguageResultExecution timeMemory
819951vjudge1Pinball (JOI14_pinball)C++17
100 / 100
441 ms63184 KiB
#include <bits/stdc++.h> using namespace std; class segtree_t { public: segtree_t *left, *right; int l, r, m; int64_t val; segtree_t(int l, int r) : l(l), r(r), m(l + r >> 1), val(1e18) { if (l == r) return; left = new segtree_t(l, m); right = new segtree_t(m + 1, r); } void Update(int p, int64_t x) { if (l == r) { val = min(val, x); return; } if (p <= m) { left->Update(p, x); } else { right->Update(p, x); } val = min(left->val, right->val); } int64_t Get(int s, int t) { if (r < s or l > t) return 1e18; if (s <= l && r <= t) return val; return min(left->Get(s, t), right->Get(s, t)); } }; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> m >> n; vector<int> a(m), b(m), c(m), d(m); for (int i = 0; i < m; i++) cin >> a[i] >> b[i] >> c[i] >> d[i]; vector<int> points({1, n}); for (int i = 0; i < m; i++) points.emplace_back(a[i]); for (int i = 0; i < m; i++) points.emplace_back(b[i]); for (int i = 0; i < m; i++) points.emplace_back(c[i]); sort(points.begin(), points.end()); points.resize(unique(points.begin(), points.end()) - points.begin()); const int N = points.size(); for (int i = 0; i < m; i++) a[i] = lower_bound(points.begin(), points.end(), a[i]) - points.begin() + 1; for (int i = 0; i < m; i++) b[i] = lower_bound(points.begin(), points.end(), b[i]) - points.begin() + 1; for (int i = 0; i < m; i++) c[i] = lower_bound(points.begin(), points.end(), c[i]) - points.begin() + 1; segtree_t *treeL = new segtree_t(1, N); segtree_t *treeR = new segtree_t(1, N); treeL->Update(1, 0); treeR->Update(N, 0); int64_t res = 1e18; for (int i = 0; i < m; i++) { int64_t x = treeL->Get(a[i], b[i]); int64_t y = treeR->Get(a[i], b[i]); treeL->Update(c[i], x + d[i]); treeR->Update(c[i], y + d[i]); res = min(res, x + y + d[i]); } cout << (res == 1e18 ? -1 : res); }

Compilation message (stderr)

pinball.cpp: In constructor 'segtree_t::segtree_t(int, int)':
pinball.cpp:10:51: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   10 |         segtree_t(int l, int r) : l(l), r(r), m(l + r >> 1), val(1e18) {
      |                                                 ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...