Submission #1100236

# Submission time Handle Problem Language Result Execution time Memory
1100236 2024-10-13T10:35:09 Z _8_8_ Treatment Project (JOI20_treatment) C++17
100 / 100
2703 ms 306288 KB
#include <bits/stdc++.h>
    
using namespace std;
    
typedef long long ll;
    
const int  N = 2e5 + 12, MOD = (int)1e9 + 7;
    
const ll inf = 1e18;
ll res = inf, d[N];
int n, m, s;
struct tr{
    ll t, l, r, c;
}; 
vector<int> T;
vector<tr> a;
set<pair<ll, int>> st, x[N * 4], y[N * 4];
bool del[N];

void ins(int pos, pair<ll, int> val, bool ok, int v = 1, int tl = 1, int tr = s) {
    // cout << tl << ' ' << tr << ' ' << ok << '\n';
    if(ok) {
        x[v].insert(val);
    } else {
        y[v].insert(val);
    }
    if(tl == tr) return;
    int tm = (tl + tr) >> 1;
    if(pos <= tm) ins(pos, val, ok, v + v, tl, tm);
    else ins(pos, val, ok, v + v + 1, tm + 1, tr);
}
int pos[N];
void upd(int l, int r, ll val, ll cost, bool ok, int v = 1, int tl = 1, int tr = s) {
    if(l >  r || tl > r || l > tr) return;
    if(tl >= l && tr <= r) {
        if(ok) {
            while(!x[v].empty()) {
                auto [f, i] = (*x[v].begin());
                if(f > val) break;
                x[v].erase({f, i});
                if(!del[i]) {
                    del[i] = 1;
                    st.insert({cost + a[i].c, i});
                }
            }
        } else {
            while(!y[v].empty()) {
                auto [f, i] = (*y[v].begin());
                if(f > val) break;
                y[v].erase({f, i});
                if(!del[i]) {
                    del[i] = 1;
                    st.insert({cost + a[i].c, i});
                }
            }
        }
    } else {
        int tm = (tl + tr) >> 1;
        upd(l, r, val, cost, ok, v + v, tl, tm);
        upd(l, r, val, cost, ok, v + v + 1, tm + 1, tr);
    }
}
void test() {
    cin >> n >> m;
    a.resize(m);
    for(int i = 0; i < m; i++) {
        d[i] = inf;
        cin >> a[i].t >> a[i].l >> a[i].r >> a[i].c;
        T.push_back(a[i].t);
    }
    sort(T.begin(), T.end());
    T.resize(unique(T.begin(), T.end()) - T.begin());
    s = (int)T.size();
    for(int i = 0; i < m; i++) {
        int j = lower_bound(T.begin(), T.end(), a[i].t) - T.begin() + 1;
        pos[i] = j;
        if(a[i].l == 1) {
            del[i] = 1;
            st.insert({a[i].c, i});
        } else {
            ins(j, {a[i].l - a[i].t, i}, 1);
            ins(j, {a[i].l + a[i].t, i}, 0);
        }
    }

    while(!st.empty()) {
        auto [w, v] = (*st.begin());
        d[v] = w;
        st.erase(st.begin());
        int j = pos[v];
        upd(1, j, a[v].r - a[v].t + 1, d[v], 1);
        upd(j, s, a[v].r + a[v].t + 1, d[v], 0);
    }

    for(int i = 0; i < m; i++) {
        if(a[i].r == n) {
            res = min(res, d[i]);
        }
    }
    if(res == inf) {
        res = -1;
    }
    cout << res << '\n';
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); 
    
    int t = 1; 
    // cin >> t;
    
    while(t--) 
        test();
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 111 ms 93388 KB Output is correct
2 Correct 108 ms 93384 KB Output is correct
3 Correct 127 ms 91612 KB Output is correct
4 Correct 120 ms 91848 KB Output is correct
5 Correct 115 ms 93128 KB Output is correct
6 Correct 97 ms 93384 KB Output is correct
7 Correct 87 ms 93348 KB Output is correct
8 Correct 68 ms 93136 KB Output is correct
9 Correct 75 ms 93248 KB Output is correct
10 Correct 78 ms 93384 KB Output is correct
11 Correct 126 ms 93384 KB Output is correct
12 Correct 127 ms 93244 KB Output is correct
13 Correct 133 ms 93384 KB Output is correct
14 Correct 131 ms 93384 KB Output is correct
15 Correct 112 ms 93384 KB Output is correct
16 Correct 116 ms 93164 KB Output is correct
17 Correct 112 ms 93384 KB Output is correct
18 Correct 128 ms 93384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 76368 KB Output is correct
2 Correct 14 ms 76368 KB Output is correct
3 Correct 12 ms 76368 KB Output is correct
4 Correct 13 ms 76368 KB Output is correct
5 Correct 15 ms 76368 KB Output is correct
6 Correct 15 ms 76368 KB Output is correct
7 Correct 14 ms 76372 KB Output is correct
8 Correct 13 ms 76368 KB Output is correct
9 Correct 12 ms 76368 KB Output is correct
10 Correct 12 ms 76368 KB Output is correct
11 Correct 13 ms 76368 KB Output is correct
12 Correct 14 ms 76288 KB Output is correct
13 Correct 13 ms 76368 KB Output is correct
14 Correct 13 ms 76368 KB Output is correct
15 Correct 14 ms 76368 KB Output is correct
16 Correct 12 ms 76368 KB Output is correct
17 Correct 13 ms 76368 KB Output is correct
18 Correct 14 ms 76368 KB Output is correct
19 Correct 14 ms 76368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 76368 KB Output is correct
2 Correct 14 ms 76368 KB Output is correct
3 Correct 12 ms 76368 KB Output is correct
4 Correct 13 ms 76368 KB Output is correct
5 Correct 15 ms 76368 KB Output is correct
6 Correct 15 ms 76368 KB Output is correct
7 Correct 14 ms 76372 KB Output is correct
8 Correct 13 ms 76368 KB Output is correct
9 Correct 12 ms 76368 KB Output is correct
10 Correct 12 ms 76368 KB Output is correct
11 Correct 13 ms 76368 KB Output is correct
12 Correct 14 ms 76288 KB Output is correct
13 Correct 13 ms 76368 KB Output is correct
14 Correct 13 ms 76368 KB Output is correct
15 Correct 14 ms 76368 KB Output is correct
16 Correct 12 ms 76368 KB Output is correct
17 Correct 13 ms 76368 KB Output is correct
18 Correct 14 ms 76368 KB Output is correct
19 Correct 14 ms 76368 KB Output is correct
20 Correct 40 ms 82504 KB Output is correct
21 Correct 50 ms 82504 KB Output is correct
22 Correct 45 ms 82760 KB Output is correct
23 Correct 42 ms 82844 KB Output is correct
24 Correct 46 ms 83528 KB Output is correct
25 Correct 49 ms 84732 KB Output is correct
26 Correct 45 ms 84960 KB Output is correct
27 Correct 41 ms 84836 KB Output is correct
28 Correct 45 ms 83536 KB Output is correct
29 Correct 46 ms 84808 KB Output is correct
30 Correct 42 ms 84808 KB Output is correct
31 Correct 43 ms 84812 KB Output is correct
32 Correct 52 ms 84816 KB Output is correct
33 Correct 55 ms 84808 KB Output is correct
34 Correct 55 ms 84552 KB Output is correct
35 Correct 52 ms 84808 KB Output is correct
36 Correct 54 ms 84816 KB Output is correct
37 Correct 49 ms 84552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 93388 KB Output is correct
2 Correct 108 ms 93384 KB Output is correct
3 Correct 127 ms 91612 KB Output is correct
4 Correct 120 ms 91848 KB Output is correct
5 Correct 115 ms 93128 KB Output is correct
6 Correct 97 ms 93384 KB Output is correct
7 Correct 87 ms 93348 KB Output is correct
8 Correct 68 ms 93136 KB Output is correct
9 Correct 75 ms 93248 KB Output is correct
10 Correct 78 ms 93384 KB Output is correct
11 Correct 126 ms 93384 KB Output is correct
12 Correct 127 ms 93244 KB Output is correct
13 Correct 133 ms 93384 KB Output is correct
14 Correct 131 ms 93384 KB Output is correct
15 Correct 112 ms 93384 KB Output is correct
16 Correct 116 ms 93164 KB Output is correct
17 Correct 112 ms 93384 KB Output is correct
18 Correct 128 ms 93384 KB Output is correct
19 Correct 11 ms 76368 KB Output is correct
20 Correct 14 ms 76368 KB Output is correct
21 Correct 12 ms 76368 KB Output is correct
22 Correct 13 ms 76368 KB Output is correct
23 Correct 15 ms 76368 KB Output is correct
24 Correct 15 ms 76368 KB Output is correct
25 Correct 14 ms 76372 KB Output is correct
26 Correct 13 ms 76368 KB Output is correct
27 Correct 12 ms 76368 KB Output is correct
28 Correct 12 ms 76368 KB Output is correct
29 Correct 13 ms 76368 KB Output is correct
30 Correct 14 ms 76288 KB Output is correct
31 Correct 13 ms 76368 KB Output is correct
32 Correct 13 ms 76368 KB Output is correct
33 Correct 14 ms 76368 KB Output is correct
34 Correct 12 ms 76368 KB Output is correct
35 Correct 13 ms 76368 KB Output is correct
36 Correct 14 ms 76368 KB Output is correct
37 Correct 14 ms 76368 KB Output is correct
38 Correct 40 ms 82504 KB Output is correct
39 Correct 50 ms 82504 KB Output is correct
40 Correct 45 ms 82760 KB Output is correct
41 Correct 42 ms 82844 KB Output is correct
42 Correct 46 ms 83528 KB Output is correct
43 Correct 49 ms 84732 KB Output is correct
44 Correct 45 ms 84960 KB Output is correct
45 Correct 41 ms 84836 KB Output is correct
46 Correct 45 ms 83536 KB Output is correct
47 Correct 46 ms 84808 KB Output is correct
48 Correct 42 ms 84808 KB Output is correct
49 Correct 43 ms 84812 KB Output is correct
50 Correct 52 ms 84816 KB Output is correct
51 Correct 55 ms 84808 KB Output is correct
52 Correct 55 ms 84552 KB Output is correct
53 Correct 52 ms 84808 KB Output is correct
54 Correct 54 ms 84816 KB Output is correct
55 Correct 49 ms 84552 KB Output is correct
56 Correct 1220 ms 239132 KB Output is correct
57 Correct 1265 ms 239056 KB Output is correct
58 Correct 1564 ms 288968 KB Output is correct
59 Correct 1359 ms 288772 KB Output is correct
60 Correct 1306 ms 260536 KB Output is correct
61 Correct 1510 ms 288904 KB Output is correct
62 Correct 1269 ms 239224 KB Output is correct
63 Correct 1561 ms 302396 KB Output is correct
64 Correct 1535 ms 305512 KB Output is correct
65 Correct 204 ms 109068 KB Output is correct
66 Correct 1393 ms 264148 KB Output is correct
67 Correct 1477 ms 304076 KB Output is correct
68 Correct 1142 ms 305896 KB Output is correct
69 Correct 1140 ms 304568 KB Output is correct
70 Correct 1852 ms 304692 KB Output is correct
71 Correct 1422 ms 305908 KB Output is correct
72 Correct 1220 ms 306144 KB Output is correct
73 Correct 1963 ms 304612 KB Output is correct
74 Correct 1121 ms 306060 KB Output is correct
75 Correct 958 ms 306140 KB Output is correct
76 Correct 2009 ms 296652 KB Output is correct
77 Correct 2372 ms 306124 KB Output is correct
78 Correct 2310 ms 296728 KB Output is correct
79 Correct 2396 ms 306124 KB Output is correct
80 Correct 2059 ms 296620 KB Output is correct
81 Correct 2025 ms 306076 KB Output is correct
82 Correct 2372 ms 295708 KB Output is correct
83 Correct 2586 ms 304844 KB Output is correct
84 Correct 2703 ms 305268 KB Output is correct
85 Correct 2095 ms 306116 KB Output is correct
86 Correct 2299 ms 306124 KB Output is correct
87 Correct 2336 ms 306176 KB Output is correct
88 Correct 1928 ms 306236 KB Output is correct
89 Correct 2172 ms 306152 KB Output is correct
90 Correct 2053 ms 306104 KB Output is correct
91 Correct 2316 ms 306124 KB Output is correct
92 Correct 2361 ms 306212 KB Output is correct
93 Correct 2488 ms 306124 KB Output is correct
94 Correct 2165 ms 306092 KB Output is correct
95 Correct 2243 ms 306212 KB Output is correct
96 Correct 2361 ms 306180 KB Output is correct
97 Correct 2402 ms 306288 KB Output is correct
98 Correct 2527 ms 306124 KB Output is correct
99 Correct 2308 ms 306124 KB Output is correct
100 Correct 1866 ms 284708 KB Output is correct
101 Correct 2437 ms 306212 KB Output is correct
102 Correct 2419 ms 306212 KB Output is correct
103 Correct 2421 ms 306124 KB Output is correct