Submission #258983

#TimeUsernameProblemLanguageResultExecution timeMemory
258983BruteforcemanTreatment Project (JOI20_treatment)C++11
100 / 100
1024 ms75088 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; const long long inf = 1e16; long long d[maxn]; struct data { int t, l, r, c; } a[maxn]; int n; bool done[maxn]; bool isEdge(data p, data q) { if(p.t <= q.t) { return q.l + q.t <= p.r + p.t; } else { return q.l - q.t <= p.r - p.t; } } struct ds { vector <pair <int, int>> t[maxn * 4]; ds () {} void add(int x, int y, int idx, int c, int b, int e) { t[c].push_back(make_pair(y, idx)); if(b == e) { return ; } int m = (b + e) >> 1; int l = c << 1; int r = l + 1; if(x <= m) add(x, y, idx, l, b, m); else add(x, y, idx, r, m + 1, e); } void init(int c, int b, int e) { sort(t[c].begin(), t[c].end(), greater <pair <int, int>> ()); if(b == e) return ; int m = (b + e) >> 1; int l = c << 1; int r = l + 1; init(l, b, m); init(r, m + 1, e); } void get(int x, int y, int val, vector <int> &v, int c, int b, int e) { if(x > y) return ; if(x <= b && e <= y) { while(!t[c].empty() && t[c].back().first <= val) { v.push_back(t[c].back().second); t[c].pop_back(); } return ; } if(y < b || e < x) return ; int m = (b + e) >> 1; int l = c << 1; int r = l + 1; get(x, y, val, v, l, b, m); get(x, y, val, v, r, m + 1, e); } } S, T; int main() { int m; scanf("%d %d", &n, &m); map <int, int> cmp; for(int i = 1; i <= m; i++) { scanf("%d %d %d %d", &a[i].t, &a[i].l, &a[i].r, &a[i].c); a[i].l -= 1; cmp[a[i].t]; } int idx = 0; for(auto &i : cmp) i.second = ++idx; priority_queue <pair <long long, int>, vector <pair <long long, int>>, greater <pair <long long, int>>> Q; for(int i = 1; i <= m; i++) { if(a[i].l == 0) { d[i] = a[i].c; Q.emplace(d[i], i); } else { d[i] = inf; } S.add(cmp[a[i].t], a[i].l - a[i].t, i, 1, 1, idx); T.add(cmp[a[i].t], a[i].l + a[i].t, i, 1, 1, idx); } S.init(1, 1, idx); T.init(1, 1, idx); while(!Q.empty()) { int node = Q.top().second; long long dist = Q.top().first; Q.pop(); if(done[node]) continue; done[node] = true; vector <int> v; S.get(1, cmp[a[node].t], a[node].r - a[node].t, v, 1, 1, idx); T.get(cmp[a[node].t], idx, a[node].r + a[node].t, v, 1, 1, idx); for(int i : v) { if(d[i] > d[node] + a[i].c) { d[i] = d[node] + a[i].c; Q.emplace(d[i], i); } } } long long ans = inf; for(int i = 1; i <= m; i++) { if(a[i].r == n) ans = min(ans, d[i]); } if(ans == inf) ans = -1; printf("%lld\n", ans); return 0; }

Compilation message (stderr)

treatment.cpp: In function 'int main()':
treatment.cpp:90:15: warning: unused variable 'dist' [-Wunused-variable]
     long long dist = Q.top().first;
               ^~~~
treatment.cpp:64:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &n, &m);
   ~~~~~^~~~~~~~~~~~~~~~~
treatment.cpp:67:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d %d", &a[i].t, &a[i].l, &a[i].r, &a[i].c);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...