Submission #946788

#TimeUsernameProblemLanguageResultExecution timeMemory
946788vjudge1Treatment Project (JOI20_treatment)C++17
4 / 100
85 ms11600 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define ar array #define pb push_back #define ln '\n' #define int long long using i64 = long long; template <class F, class _S> bool chmin(F &u, const _S &v){ bool flag = false; if ( u > v ){ u = v; flag |= true; } return flag; } template <class F, class _S> bool chmax(F &u, const _S &v){ bool flag = false; if ( u < v ){ u = v; flag |= true; } return flag; } const int N = 1e5 + 1; const int inf = 1e15; int m; struct SegTree{ int T[N * 4]; SegTree(){ for ( int i = 0; i < N * 4; i++ ){ T[i] = inf; } } void upd(int v, int l, int r, int pos, int vl){ if ( l == r ){ T[v] = vl; return; } int md = (l + r) >> 1; if ( pos <= md ){ upd(v * 2, l, md, pos, vl); } else{ upd(v * 2 + 1, md + 1, r, pos, vl); } T[v] = min(T[v * 2], T[v * 2 + 1]); } void upd(int pos, int vl){ upd(1, 0, m - 1, pos, vl); } int get(int v, int l, int r, int tl, int tr){ if ( l > tr or r < tl ){ return inf; } if ( tl <= l && tr >= r ){ return T[v]; } int md = (l + r) >> 1; return min(get(v * 2, l, md, tl, tr), get(v * 2 + 1, md + 1, r, tl, tr)); } int get(int l, int r){ return get(1, 0, m - 1, l, r); } } seg; signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n >> m; vector <int> T(m), L(m), R(m), C(m); for ( int i = 0; i < m; i++ ){ cin >> T[i] >> L[i] >> R[i] >> C[i]; } if ( *max_element(all(T)) == 1 ){ vector <int> p(m); iota(all(p), 0); sort(all(p), [&](int &u, int &v){ return R[u] < R[v]; }); vector <int> dp(m, inf); int opt = inf; for ( int i = 0; i < m; i++ ){ int j = p[i]; if ( L[j] == 1 ){ dp[i] = C[j]; } else{ int l = 0, r = i; while ( l < r ){ int md = (l + r) >> 1; if ( R[p[md]] + 1 >= L[j] ){ r = md; } else l = md + 1; } chmin(dp[i], seg.get(l, i) + C[j]); } seg.upd(i, dp[i]); if ( R[j] == n ){ chmin(opt, dp[i]); } } cout << (opt == inf ? -1 : opt); return 0; } cout << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...