Submission #537994

#TimeUsernameProblemLanguageResultExecution timeMemory
5379948e7Treatment Project (JOI20_treatment)C++17
100 / 100
247 ms62516 KiB
//Challenge: Accepted #include <bits/stdc++.h> using namespace std; #ifdef zisk void debug(){cout << endl;} template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);} template<class T> void pary(T l, T r) { while (l != r) cout << *l << " ", l++; cout << endl; } #else #define debug(...) 0 #define pary(...) 0 #endif #define ll long long #define maxn 100005 #define pii pair<ll, ll> #define ff first #define ss second #define io ios_base::sync_with_stdio(0);cin.tie(0); const ll inf = 1LL<<60; vector<pii> lef[maxn]; struct segtree{ vector<pii> seg[4*maxn]; void init(int cur, int l, int r) { if (r <= l) return; if (r - l == 1) { seg[cur] = lef[l]; return; } int m = (l + r) / 2; init(cur*2, l, m), init(cur*2+1, m, r); int ind = 0; for (int i = 0;i < seg[cur*2].size();i++) { while (ind < seg[cur*2+1].size() && seg[cur*2+1][ind] > seg[cur*2][i]) { seg[cur].push_back(seg[cur*2+1][ind++]); } seg[cur].push_back(seg[cur*2][i]); } while (ind < seg[cur*2+1].size()) { seg[cur].push_back(seg[cur*2+1][ind++]); } } void getind(int cur, int l, int r, int ql, int qr, int y, vector<int> &ret, bool add) { if (r <= l || ql >= r || qr <= l || seg[cur].size() == 0 || seg[cur].back().ff > y) return; if (ql <= l && qr >= r) { while (seg[cur].size() && seg[cur].back().ff <= y) { if (add) ret.push_back(seg[cur].back().ss); seg[cur].pop_back(); } add = 0; } if (r - l == 1) return; int m = (l + r) / 2; getind(cur*2, l, m, ql, qr, y, ret, add); getind(cur*2+1, m, r, ql, qr, y, ret, add); } } tr; struct seg{ int t, l, r, x, y; int cost; seg(){t = l = r = cost = 0;} } a[maxn]; ll dis[maxn]; int main() { io int L, n; cin >> L >> n; vector<int> vx; for (int i = 1;i <= n;i++) { cin >> a[i].t >> a[i].l >> a[i].r >> a[i].cost; a[i].x = a[i].l - a[i].t; a[i].y = a[i].l + a[i].t; vx.push_back(a[i].x); } sort(vx.begin(), vx.end()); vx.resize(int(unique(vx.begin(), vx.end()) - vx.begin())); for (int i = 1;i <= n;i++) { a[i].x = lower_bound(vx.begin(), vx.end(), a[i].x) - vx.begin(); lef[a[i].x].push_back({a[i].y, i}); } for (int i = 0;i < n;i++) sort(lef[i].begin(), lef[i].end(), [&](pii x, pii y){return x > y;}); tr.init(1, 0, n); priority_queue<pii, vector<pii>, greater<pii> > pq; for (int i = 1;i <= n;i++) { dis[i] = inf; if (a[i].l == 1) { dis[i] = a[i].cost; pq.push({dis[i], i}); } } dis[n+1] = inf; while (pq.size()) { auto [d, cur] = pq.top(); pq.pop(); if (d != dis[cur]) continue; if (a[cur].r == L) dis[n+1] = min(dis[n+1], d); vector<int> upd; int xv = upper_bound(vx.begin(), vx.end(), a[cur].r - a[cur].t + 1) - vx.begin(); tr.getind(1, 0, n, 0, xv, a[cur].r + a[cur].t + 1, upd, 1); debug(cur, d, xv); for (int i:upd) { if (d + a[i].cost < dis[i]) { dis[i] = d + a[i].cost; pq.push({dis[i], i}); } } } cout << (dis[n+1] == inf ? -1 : dis[n+1]) << "\n"; } /* 1000000000 16 6 2 2 1 4 999999997 999999999 4 2 999999997 1000000000 2 3 1 4 3 3 999999997 1000000000 3 5 999999998 999999999 3 6 999999999 999999999 1 2 1 4 2 6 3 999999998 1 999999987 1 1000000000 10 999999986 1 1000000000 10 999999985 1 1000000000 10 4 2 4 4 5 2 3 3 1 999999997 1000000000 1 1 1 4 1 */

Compilation message (stderr)

treatment.cpp: In member function 'void segtree::init(int, int, int)':
treatment.cpp:35:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   for (int i = 0;i < seg[cur*2].size();i++) {
      |                  ~~^~~~~~~~~~~~~~~~~~~
treatment.cpp:36:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |    while (ind < seg[cur*2+1].size() && seg[cur*2+1][ind] > seg[cur*2][i]) {
      |           ~~~~^~~~~~~~~~~~~~~~~~~~~
treatment.cpp:41:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |   while (ind < seg[cur*2+1].size()) {
      |          ~~~~^~~~~~~~~~~~~~~~~~~~~
treatment.cpp: In function 'int main()':
treatment.cpp:12:20: warning: statement has no effect [-Wunused-value]
   12 | #define debug(...) 0
      |                    ^
treatment.cpp:104:3: note: in expansion of macro 'debug'
  104 |   debug(cur, d, xv);
      |   ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...