Submission #216780

#TimeUsernameProblemLanguageResultExecution timeMemory
216780abacabaTreatment Project (JOI20_treatment)C++14
100 / 100
930 ms72016 KiB
#include <iostream> #include <string> #include <unordered_map> #include <unordered_set> #include <cstring> #include <chrono> #include <vector> #include <map> #include <random> #include <set> #include <algorithm> #include <math.h> #include <cstdio> #include <stdio.h> #include <queue> #include <bitset> #include <cstdlib> #include <deque> #include <cassert> #include <stack> using namespace std; #define mp make_pair #define f first #define se second #define pb push_back #define ppb pop_back #define ll long long #define ull unsigned long long #define cntbit(x) __builtin_popcount(x) #define endl '\n' #define uset unordered_set #define umap unordered_map #define all(x) x.begin(), x.end() #define pii pair<int, int> #define ld long double #define pll pair<long long, long long> mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template <typename T> inline T range(T l, T r) { return uniform_int_distribution <T>(l, r)(rng); } template <typename T> void Min(T &a, T b) { a = min(a, b); } template <typename T> void Max(T &a, T b) { a = max(a, b); } const int mod = 1e9 + 7; const ll inf = 2e18; const int N = 1e5 + 15; int n, m; ll ans = -1; vector <int> compress; int sz; ll d[N]; priority_queue <pair <ll, int>, vector <pair <ll, int>>, greater <pair <ll, int>>> q; inline int gt(int x) { return lower_bound(compress.begin(), compress.end(), x) - compress.begin() + 1; } struct pt { int t, l, r, c; } a[N]; struct segment_tree { priority_queue <pii, vector <pii>, greater <pii>> t[N << 2]; void get(int v, int tl, int tr, int l, int r, int val, ll nw) { if(tl > r || tr < l) return; if(tl >= l && tr <= r) { while(!t[v].empty() && t[v].top().f <= val) { int i = t[v].top().se; if(d[i] > nw + a[i].c) q.push(mp(d[i] = nw + a[i].c, i)); t[v].pop(); } return; } int mid = tl + tr >> 1; get(v << 1, tl, mid, l, r, val, nw); get(v << 1 | 1, mid + 1, tr, l, r, val, nw); } inline void update(int v, int tl, int tr, int pos, pii val) { while(1) { t[v].push(val); if(tl == tr) break; int mid = tl + tr >> 1; if(pos <= mid) v <<= 1, tr = mid; else v = v << 1 | 1, tl = mid + 1; } } } t1, t2; inline int nxt() { int x; scanf("%d", &x); return x; } main() { fill(d, d + N, inf); n = nxt(); m = nxt(); for(int i = 1; i <= m; ++i) { a[i].t = nxt(); a[i].l = nxt(); a[i].r = nxt(); a[i].c = nxt(); compress.pb(a[i].t); } sort(compress.begin(), compress.end()); compress.erase(unique(compress.begin(), compress.end()), compress.end()); sz = compress.size(); for(int i = 1; i <= m; ++i) { --a[i].l; if(a[i].l == 0) { d[i] = a[i].c; q.push({d[i], i}); } else { t1.update(1, 1, sz, gt(a[i].t), mp(a[i].l + a[i].t, i)); t2.update(1, 1, sz, gt(a[i].t), mp(a[i].l - a[i].t, i)); } } while(!q.empty()) { int dist = q.top().f, i = q.top().se; q.pop(); if(dist > d[i]) continue; t1.get(1, 1, sz, gt(a[i].t), sz, a[i].r + a[i].t, d[i]); t2.get(1, 1, sz, 1, gt(a[i].t), a[i].r - a[i].t, d[i]); } for(int i = 1; i <= m; ++i) { if(a[i].r != n || d[i] == inf) continue; if(ans == -1 || d[i] < ans) ans = d[i]; } cout << ans << endl; return 0; }

Compilation message (stderr)

treatment.cpp: In member function 'void segment_tree::get(int, int, int, int, int, int, long long int)':
treatment.cpp:88:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid = tl + tr >> 1;
             ~~~^~~~
treatment.cpp: In member function 'void segment_tree::update(int, int, int, int, std::pair<int, int>)':
treatment.cpp:99:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    int mid = tl + tr >> 1;
              ~~~^~~~
treatment.cpp: At global scope:
treatment.cpp:114:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
treatment.cpp: In function 'int nxt()':
treatment.cpp:110:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &x);
  ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...