Submission #955882

#TimeUsernameProblemLanguageResultExecution timeMemory
955882VMaksimoski008Pinball (JOI14_pinball)C++14
100 / 100
357 ms41428 KiB
#include <bits/stdc++.h> #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() using namespace std; using ll = long long; const int maxn = 1e5 + 5; ll dpL[maxn], dpR[maxn]; struct SegTree { int n; vector<ll> tree; SegTree(int _n) : n(_n), tree(4*_n+5, 1e18) {} void update(int u, int tl, int tr, int p, ll v) { if(tl == tr) { tree[u] = min(tree[u], v); } else { int tm = (tl + tr) / 2; if(p <= tm) update(2*u, tl, tm, p, v); else update(2*u+1, tm+1, tr, p, v); tree[u] = min(tree[2*u], tree[2*u+1]); } } ll query(int u, int tl, int tr, int l, int r) { if(tl > tr || l > tr || tl > r) return 1e18; if(l <= tl && tr <= r) return tree[u]; int tm = (tl + tr) / 2; return min( query(2*u, tl, tm, l, r), query(2*u+1, tm+1, tr, l, r) ); } void update(int p, ll v) { update(1, 0, n-1, p, v); } ll query(int l, int r) { return query(1, 0, n-1, l, r); } }; int32_t main() { int n, m; cin >> n >> m; vector<array<int, 4> > v(n+2); set<int> s; s.insert(1); s.insert(m); for(int i=1; i<=n; i++) { cin >> v[i][0] >> v[i][1] >> v[i][2] >> v[i][3]; s.insert(v[i][0]); s.insert(v[i][1]); s.insert(v[i][2]); } vector<int> comp(all(s)); for(int i=1; i<=n; i++) { v[i][0] = lower_bound(all(comp), v[i][0]) - comp.begin(); v[i][1] = lower_bound(all(comp), v[i][1]) - comp.begin(); v[i][2] = lower_bound(all(comp), v[i][2]) - comp.begin(); } ll ans = 1e18; for(int i=1; i<=n; i++) dpL[i] = dpR[i] = 1e18; auto check = [&](int i, int j) { return v[i][0] <= v[j][2] && v[j][2] <= v[i][1]; }; SegTree treeL(comp.size()), treeR(comp.size()); for(int i=1; i<=n; i++) { if(v[i][0] == 0) dpL[i] = v[i][3]; if(v[i][1] == comp.size()-1) dpR[i] = v[i][3]; dpL[i] = min(dpL[i], v[i][3] + treeL.query(v[i][0], v[i][1])); dpR[i] = min(dpR[i], v[i][3] + treeR.query(v[i][0], v[i][1])); ans = min(ans, dpL[i] + dpR[i] - v[i][3]); treeL.update(v[i][2], dpL[i]); treeR.update(v[i][2], dpR[i]); } cout << (ans == 1e18 ? -1 : ans) << '\n'; return 0; }

Compilation message (stderr)

pinball.cpp: In function 'int32_t main()':
pinball.cpp:76:20: warning: comparison of integer expressions of different signedness: 'std::array<int, 4>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |         if(v[i][1] == comp.size()-1) dpR[i] = v[i][3];
pinball.cpp:68:10: warning: variable 'check' set but not used [-Wunused-but-set-variable]
   68 |     auto check = [&](int i, int j) {
      |          ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...