답안 #424636

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
424636 2021-06-12T08:22:51 Z lyc 치료 계획 (JOI20_treatment) C++14
100 / 100
470 ms 108160 KB
#include <bits/stdc++.h>
using namespace std;

#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long ll;
typedef pair<ll,ll> pll;

const int mxM = 100001;

int N, M;
struct Treat {
    int T, L, R, C;
} treat[mxM];

bool vis[mxM];
vector<ll> vals;
priority_queue<pll,vector<pll>,greater<pll>> pq;

struct node {
    int s, e, m;
    vector<pll> v;
    node *l, *r;
    node(int s, int e): s(s), e(e), m((s+e)/2) {
        if (s != e) {
            l = new node(s,m);
            r = new node(m+1,e);
        }
    }

    void update(int a, pll b) {
        if (s == e) v.push_back(b);
        else if (a <= m) l->update(a,b);
        else r->update(a,b);
    }

    void build() {
        if (s == e) {
            sort(v.rbegin(),v.rend());
        } else {
            l->build();
            r->build();
            auto& a = l->v, b = r->v;
            for (int i = 0, j = 0; i < SZ(a) || j < SZ(b);) {
                if (i < SZ(a) && (j == SZ(b) || a[i] > b[j]))
                    v.push_back(a[i++]);
                else
                    v.push_back(b[j++]);
            }
        }
        //cout << s _ e << ": ";
        //for (auto& x : v) { cout << x.first _ x.second << ", "; } cout << endl;
    }

    void proc(int a, int b, ll x, ll w) {
        if (a > b) return;
        if (a <= s && e <= b) {
            while (SZ(v) && v.back().first <= x) {
                auto i = v.back().second; v.pop_back();
                if (vis[i]) continue;
                vis[i] = 1;
                //cout << "PUSH" _ vals[treat[i].T] _ treat[i].L _ treat[i].R << endl;
                pq.push(pll(w + treat[i].C, i));
            }
        } else {
            if (a <= m) l->proc(a,b,x,w);
            if (b > m) r->proc(a,b,x,w);
        }
    }
} *root1, *root2;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> N >> M;
    FOR(i,1,M){
        int T, L, R, C;
        cin >> T >> L >> R >> C;
        treat[i] = {T,L,R,C};
        vals.push_back(T);
    }
    sort(ALL(vals));
    vals.resize(unique(ALL(vals))-vals.begin());

    root1 = new node(0,SZ(vals)-1);
    root2 = new node(0,SZ(vals)-1);

    memset(vis,0,sizeof vis);

    FOR(i,1,M){
        auto& t = treat[i];
        t.T = lower_bound(ALL(vals),t.T)-vals.begin();

        //cout << i _ t.T _ t.L+vals[t.T]-1 _ t.L-vals[t.T]-1 << endl;
        //cout << i _ t.T _ t.R+vals[t.T] _ t.R-vals[t.T]-1 << endl;
        if (t.L == 1) {
            vis[i] = 1;
            pq.push(pll(t.C,i));
        } else {
            root1->update(t.T, pll(t.L+vals[t.T]-1,i));
            root2->update(t.T, pll(t.L-vals[t.T]-1,i));
        }
    }

    root1->build();
    root2->build();

    while (!pq.empty()) {
        auto [w, u] = pq.top(); pq.pop();
        auto t = treat[u];
        //TRACE(u _ vals[t.T] _ t.L _ t.R _ w);
        if (t.R == N) {
            cout << w << '\n';
            return 0;
        }

        root1->proc(t.T, SZ(vals)-1, t.R+vals[t.T], w);
        root2->proc(0, t.T-1, t.R-vals[t.T], w);
    }

    cout << -1 << '\n';
}

Compilation message

treatment.cpp: In function 'int main()':
treatment.cpp:113:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  113 |         auto [w, u] = pq.top(); pq.pop();
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 5968 KB Output is correct
2 Correct 73 ms 5920 KB Output is correct
3 Correct 74 ms 6704 KB Output is correct
4 Correct 79 ms 6596 KB Output is correct
5 Correct 75 ms 8896 KB Output is correct
6 Correct 79 ms 6100 KB Output is correct
7 Correct 76 ms 5984 KB Output is correct
8 Correct 76 ms 5936 KB Output is correct
9 Correct 69 ms 5992 KB Output is correct
10 Correct 66 ms 5912 KB Output is correct
11 Correct 78 ms 8968 KB Output is correct
12 Correct 76 ms 8888 KB Output is correct
13 Correct 80 ms 8880 KB Output is correct
14 Correct 79 ms 8976 KB Output is correct
15 Correct 83 ms 6056 KB Output is correct
16 Correct 82 ms 5960 KB Output is correct
17 Correct 74 ms 5984 KB Output is correct
18 Correct 73 ms 8960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 432 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 432 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 9 ms 3532 KB Output is correct
21 Correct 10 ms 3596 KB Output is correct
22 Correct 8 ms 3264 KB Output is correct
23 Correct 8 ms 3276 KB Output is correct
24 Correct 11 ms 4896 KB Output is correct
25 Correct 15 ms 5376 KB Output is correct
26 Correct 13 ms 5400 KB Output is correct
27 Correct 13 ms 5324 KB Output is correct
28 Correct 11 ms 4812 KB Output is correct
29 Correct 13 ms 5348 KB Output is correct
30 Correct 10 ms 5316 KB Output is correct
31 Correct 10 ms 5268 KB Output is correct
32 Correct 12 ms 5452 KB Output is correct
33 Correct 11 ms 5324 KB Output is correct
34 Correct 13 ms 4536 KB Output is correct
35 Correct 11 ms 5324 KB Output is correct
36 Correct 11 ms 5448 KB Output is correct
37 Correct 13 ms 4556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 5968 KB Output is correct
2 Correct 73 ms 5920 KB Output is correct
3 Correct 74 ms 6704 KB Output is correct
4 Correct 79 ms 6596 KB Output is correct
5 Correct 75 ms 8896 KB Output is correct
6 Correct 79 ms 6100 KB Output is correct
7 Correct 76 ms 5984 KB Output is correct
8 Correct 76 ms 5936 KB Output is correct
9 Correct 69 ms 5992 KB Output is correct
10 Correct 66 ms 5912 KB Output is correct
11 Correct 78 ms 8968 KB Output is correct
12 Correct 76 ms 8888 KB Output is correct
13 Correct 80 ms 8880 KB Output is correct
14 Correct 79 ms 8976 KB Output is correct
15 Correct 83 ms 6056 KB Output is correct
16 Correct 82 ms 5960 KB Output is correct
17 Correct 74 ms 5984 KB Output is correct
18 Correct 73 ms 8960 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 432 KB Output is correct
26 Correct 1 ms 328 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 308 KB Output is correct
37 Correct 1 ms 316 KB Output is correct
38 Correct 9 ms 3532 KB Output is correct
39 Correct 10 ms 3596 KB Output is correct
40 Correct 8 ms 3264 KB Output is correct
41 Correct 8 ms 3276 KB Output is correct
42 Correct 11 ms 4896 KB Output is correct
43 Correct 15 ms 5376 KB Output is correct
44 Correct 13 ms 5400 KB Output is correct
45 Correct 13 ms 5324 KB Output is correct
46 Correct 11 ms 4812 KB Output is correct
47 Correct 13 ms 5348 KB Output is correct
48 Correct 10 ms 5316 KB Output is correct
49 Correct 10 ms 5268 KB Output is correct
50 Correct 12 ms 5452 KB Output is correct
51 Correct 11 ms 5324 KB Output is correct
52 Correct 13 ms 4536 KB Output is correct
53 Correct 11 ms 5324 KB Output is correct
54 Correct 11 ms 5448 KB Output is correct
55 Correct 13 ms 4556 KB Output is correct
56 Correct 266 ms 71040 KB Output is correct
57 Correct 276 ms 70624 KB Output is correct
58 Correct 283 ms 85344 KB Output is correct
59 Correct 291 ms 85720 KB Output is correct
60 Correct 209 ms 68388 KB Output is correct
61 Correct 304 ms 85312 KB Output is correct
62 Correct 273 ms 71116 KB Output is correct
63 Correct 341 ms 105816 KB Output is correct
64 Correct 330 ms 105800 KB Output is correct
65 Correct 85 ms 14640 KB Output is correct
66 Correct 191 ms 68356 KB Output is correct
67 Correct 379 ms 106388 KB Output is correct
68 Correct 327 ms 106360 KB Output is correct
69 Correct 307 ms 103488 KB Output is correct
70 Correct 420 ms 106488 KB Output is correct
71 Correct 361 ms 106396 KB Output is correct
72 Correct 319 ms 106512 KB Output is correct
73 Correct 418 ms 106240 KB Output is correct
74 Correct 220 ms 106552 KB Output is correct
75 Correct 217 ms 106340 KB Output is correct
76 Correct 273 ms 93856 KB Output is correct
77 Correct 303 ms 106520 KB Output is correct
78 Correct 340 ms 93628 KB Output is correct
79 Correct 470 ms 106620 KB Output is correct
80 Correct 451 ms 92644 KB Output is correct
81 Correct 302 ms 106512 KB Output is correct
82 Correct 418 ms 91660 KB Output is correct
83 Correct 465 ms 105516 KB Output is correct
84 Correct 465 ms 105628 KB Output is correct
85 Correct 372 ms 106392 KB Output is correct
86 Correct 385 ms 106400 KB Output is correct
87 Correct 391 ms 106444 KB Output is correct
88 Correct 396 ms 106416 KB Output is correct
89 Correct 397 ms 106532 KB Output is correct
90 Correct 287 ms 107756 KB Output is correct
91 Correct 306 ms 106588 KB Output is correct
92 Correct 394 ms 106520 KB Output is correct
93 Correct 447 ms 106548 KB Output is correct
94 Correct 448 ms 106592 KB Output is correct
95 Correct 403 ms 106508 KB Output is correct
96 Correct 287 ms 106456 KB Output is correct
97 Correct 303 ms 107936 KB Output is correct
98 Correct 290 ms 108000 KB Output is correct
99 Correct 302 ms 107656 KB Output is correct
100 Correct 284 ms 103596 KB Output is correct
101 Correct 310 ms 108020 KB Output is correct
102 Correct 297 ms 108160 KB Output is correct
103 Correct 355 ms 106572 KB Output is correct