답안 #255326

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
255326 2020-07-31T17:32:17 Z model_code Fuel Station (NOI20_fuelstation) C++17
100 / 100
1163 ms 47020 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
using namespace std;

typedef pair<int, int> pi;
int N, D;
struct station {
    int X, A, B;
    station() {}
    station(int _X, int _A, int _B): X(_X), A(_A), B(_B) {}
    bool operator <(const station &o) const {
        return tie(X, A, B) < tie(o.X, o.A, o.B);
    }
} STN[300010];

struct node {
    int S, E, M;
    int64_t LAZY, V; // Min val
    node *L, *R;
    node(int _S, int _E): S(_S), E(_E), M((_S + _E) / 2) {
        V = LAZY = 0;
        if (S == E) return;
        L = new node(S, M); R = new node(M + 1, E);
    }
    int64_t val() {
        return V + LAZY;
    }
    void push() {
        if (LAZY) {
            L->LAZY += LAZY;
            R->LAZY += LAZY;
            V += LAZY;
            LAZY = 0;
        }
    }
    void update(int QS, int QE, int QV) { // Range Update Add
        if (QS <= S && E <= QE) return (void)(LAZY += QV);
        push();
        if (QE <= M) L->update(QS, QE, QV);
        else if (QS > M) R->update(QS, QE, QV);
        else { L->update(QS, M, QV); R->update(M + 1, QE, QV); }
        V = min(L->val(), R->val());
    }
} *root;

vector<pi> V;
int NXT[300010];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> D;
    root = new node(1, N + 1);
    for (int a = 1; a <= N; ++a) cin >> STN[a].X >> STN[a].A >> STN[a].B;
    sort(STN + 1, STN + N + 1);
    int XPTR = 1;
    STN[N + 1] = station(D, 0, D);
    for (int a = 1; a <= N + 1; ++a) if (STN[a].X != STN[XPTR].X)
        for (; XPTR < a; ++XPTR) NXT[XPTR] = a;
    NXT[N + 1] = N + 1;
    for (int a = 1; a <= N + 1; ++a) V.emplace_back(STN[a].B, a);
    sort(V.begin(), V.end()); // Sort by B
    for (int a = 0; a <= N; ++a) root->update(V[a].second, V[a].second, -STN[V[a].second].X); // -X to this location
    for (int a = 0; a <= N; ++a)
        root->update(NXT[V[a].second], N + 1, STN[V[a].second].A); // +A to locations after
    int F = 0, BPTR = 0;
    for (int a = 0; a <= N; ++a) {
        root->update(1, N + 1, V[a].first - F); // Increase in fuel
        if (a && V[a].first != F)
            for (; BPTR < a; ++BPTR)
                root->update(NXT[V[BPTR].second], N + 1, -STN[V[BPTR].second].A); // Remove station
        F = V[a].first;
        int64_t mval = root->val();
        if (mval >= 0) {
            cout << F - mval << '\n';
            return 0;
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 298 ms 46852 KB Output is correct
2 Correct 287 ms 47020 KB Output is correct
3 Correct 336 ms 46908 KB Output is correct
4 Correct 341 ms 46880 KB Output is correct
5 Correct 402 ms 46820 KB Output is correct
6 Correct 359 ms 46956 KB Output is correct
7 Correct 376 ms 46908 KB Output is correct
8 Correct 322 ms 46828 KB Output is correct
9 Correct 373 ms 46824 KB Output is correct
10 Correct 322 ms 46828 KB Output is correct
11 Correct 338 ms 46812 KB Output is correct
12 Correct 286 ms 46804 KB Output is correct
13 Correct 344 ms 46860 KB Output is correct
14 Correct 296 ms 46876 KB Output is correct
15 Correct 288 ms 46956 KB Output is correct
16 Correct 307 ms 46984 KB Output is correct
17 Correct 299 ms 46828 KB Output is correct
18 Correct 312 ms 46852 KB Output is correct
19 Correct 339 ms 46828 KB Output is correct
20 Correct 296 ms 46828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 14 ms 2048 KB Output is correct
3 Correct 7 ms 2024 KB Output is correct
4 Correct 10 ms 1968 KB Output is correct
5 Correct 10 ms 1920 KB Output is correct
6 Correct 16 ms 1920 KB Output is correct
7 Correct 13 ms 1920 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 13 ms 1920 KB Output is correct
15 Correct 18 ms 1920 KB Output is correct
16 Correct 14 ms 1920 KB Output is correct
17 Correct 13 ms 1920 KB Output is correct
18 Correct 16 ms 1920 KB Output is correct
19 Correct 10 ms 1920 KB Output is correct
20 Correct 11 ms 1920 KB Output is correct
21 Correct 9 ms 1920 KB Output is correct
22 Correct 10 ms 1920 KB Output is correct
23 Correct 9 ms 1920 KB Output is correct
24 Correct 11 ms 1920 KB Output is correct
25 Correct 12 ms 1968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 14 ms 2048 KB Output is correct
3 Correct 7 ms 2024 KB Output is correct
4 Correct 10 ms 1968 KB Output is correct
5 Correct 10 ms 1920 KB Output is correct
6 Correct 16 ms 1920 KB Output is correct
7 Correct 13 ms 1920 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 13 ms 1920 KB Output is correct
15 Correct 18 ms 1920 KB Output is correct
16 Correct 14 ms 1920 KB Output is correct
17 Correct 13 ms 1920 KB Output is correct
18 Correct 16 ms 1920 KB Output is correct
19 Correct 10 ms 1920 KB Output is correct
20 Correct 11 ms 1920 KB Output is correct
21 Correct 9 ms 1920 KB Output is correct
22 Correct 10 ms 1920 KB Output is correct
23 Correct 9 ms 1920 KB Output is correct
24 Correct 11 ms 1920 KB Output is correct
25 Correct 12 ms 1968 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 530 ms 46956 KB Output is correct
28 Correct 726 ms 46904 KB Output is correct
29 Correct 656 ms 46852 KB Output is correct
30 Correct 630 ms 46828 KB Output is correct
31 Correct 780 ms 46828 KB Output is correct
32 Correct 786 ms 46824 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 755 ms 46828 KB Output is correct
40 Correct 747 ms 46828 KB Output is correct
41 Correct 837 ms 46828 KB Output is correct
42 Correct 743 ms 46864 KB Output is correct
43 Correct 812 ms 46864 KB Output is correct
44 Correct 425 ms 46828 KB Output is correct
45 Correct 334 ms 46828 KB Output is correct
46 Correct 678 ms 46828 KB Output is correct
47 Correct 363 ms 46828 KB Output is correct
48 Correct 311 ms 46828 KB Output is correct
49 Correct 609 ms 46856 KB Output is correct
50 Correct 524 ms 46828 KB Output is correct
51 Correct 533 ms 46828 KB Output is correct
52 Correct 618 ms 46832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 14 ms 2048 KB Output is correct
18 Correct 7 ms 2024 KB Output is correct
19 Correct 10 ms 1968 KB Output is correct
20 Correct 10 ms 1920 KB Output is correct
21 Correct 16 ms 1920 KB Output is correct
22 Correct 13 ms 1920 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 13 ms 1920 KB Output is correct
30 Correct 18 ms 1920 KB Output is correct
31 Correct 14 ms 1920 KB Output is correct
32 Correct 13 ms 1920 KB Output is correct
33 Correct 16 ms 1920 KB Output is correct
34 Correct 10 ms 1920 KB Output is correct
35 Correct 11 ms 1920 KB Output is correct
36 Correct 9 ms 1920 KB Output is correct
37 Correct 10 ms 1920 KB Output is correct
38 Correct 9 ms 1920 KB Output is correct
39 Correct 11 ms 1920 KB Output is correct
40 Correct 12 ms 1968 KB Output is correct
41 Correct 0 ms 384 KB Output is correct
42 Correct 12 ms 1920 KB Output is correct
43 Correct 12 ms 1968 KB Output is correct
44 Correct 15 ms 1968 KB Output is correct
45 Correct 13 ms 1920 KB Output is correct
46 Correct 11 ms 1920 KB Output is correct
47 Correct 13 ms 1968 KB Output is correct
48 Correct 0 ms 384 KB Output is correct
49 Correct 0 ms 384 KB Output is correct
50 Correct 1 ms 384 KB Output is correct
51 Correct 0 ms 384 KB Output is correct
52 Correct 1 ms 384 KB Output is correct
53 Correct 0 ms 384 KB Output is correct
54 Correct 15 ms 1920 KB Output is correct
55 Correct 17 ms 1920 KB Output is correct
56 Correct 17 ms 1920 KB Output is correct
57 Correct 17 ms 1920 KB Output is correct
58 Correct 20 ms 2072 KB Output is correct
59 Correct 16 ms 1920 KB Output is correct
60 Correct 10 ms 1920 KB Output is correct
61 Correct 12 ms 1920 KB Output is correct
62 Correct 14 ms 1920 KB Output is correct
63 Correct 12 ms 1920 KB Output is correct
64 Correct 13 ms 1960 KB Output is correct
65 Correct 15 ms 1968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 298 ms 46852 KB Output is correct
17 Correct 287 ms 47020 KB Output is correct
18 Correct 336 ms 46908 KB Output is correct
19 Correct 341 ms 46880 KB Output is correct
20 Correct 402 ms 46820 KB Output is correct
21 Correct 359 ms 46956 KB Output is correct
22 Correct 376 ms 46908 KB Output is correct
23 Correct 322 ms 46828 KB Output is correct
24 Correct 373 ms 46824 KB Output is correct
25 Correct 322 ms 46828 KB Output is correct
26 Correct 338 ms 46812 KB Output is correct
27 Correct 286 ms 46804 KB Output is correct
28 Correct 344 ms 46860 KB Output is correct
29 Correct 296 ms 46876 KB Output is correct
30 Correct 288 ms 46956 KB Output is correct
31 Correct 307 ms 46984 KB Output is correct
32 Correct 299 ms 46828 KB Output is correct
33 Correct 312 ms 46852 KB Output is correct
34 Correct 339 ms 46828 KB Output is correct
35 Correct 296 ms 46828 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 14 ms 2048 KB Output is correct
38 Correct 7 ms 2024 KB Output is correct
39 Correct 10 ms 1968 KB Output is correct
40 Correct 10 ms 1920 KB Output is correct
41 Correct 16 ms 1920 KB Output is correct
42 Correct 13 ms 1920 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 0 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 0 ms 384 KB Output is correct
49 Correct 13 ms 1920 KB Output is correct
50 Correct 18 ms 1920 KB Output is correct
51 Correct 14 ms 1920 KB Output is correct
52 Correct 13 ms 1920 KB Output is correct
53 Correct 16 ms 1920 KB Output is correct
54 Correct 10 ms 1920 KB Output is correct
55 Correct 11 ms 1920 KB Output is correct
56 Correct 9 ms 1920 KB Output is correct
57 Correct 10 ms 1920 KB Output is correct
58 Correct 9 ms 1920 KB Output is correct
59 Correct 11 ms 1920 KB Output is correct
60 Correct 12 ms 1968 KB Output is correct
61 Correct 0 ms 384 KB Output is correct
62 Correct 530 ms 46956 KB Output is correct
63 Correct 726 ms 46904 KB Output is correct
64 Correct 656 ms 46852 KB Output is correct
65 Correct 630 ms 46828 KB Output is correct
66 Correct 780 ms 46828 KB Output is correct
67 Correct 786 ms 46824 KB Output is correct
68 Correct 1 ms 384 KB Output is correct
69 Correct 1 ms 384 KB Output is correct
70 Correct 1 ms 384 KB Output is correct
71 Correct 1 ms 384 KB Output is correct
72 Correct 1 ms 384 KB Output is correct
73 Correct 0 ms 384 KB Output is correct
74 Correct 755 ms 46828 KB Output is correct
75 Correct 747 ms 46828 KB Output is correct
76 Correct 837 ms 46828 KB Output is correct
77 Correct 743 ms 46864 KB Output is correct
78 Correct 812 ms 46864 KB Output is correct
79 Correct 425 ms 46828 KB Output is correct
80 Correct 334 ms 46828 KB Output is correct
81 Correct 678 ms 46828 KB Output is correct
82 Correct 363 ms 46828 KB Output is correct
83 Correct 311 ms 46828 KB Output is correct
84 Correct 609 ms 46856 KB Output is correct
85 Correct 524 ms 46828 KB Output is correct
86 Correct 533 ms 46828 KB Output is correct
87 Correct 618 ms 46832 KB Output is correct
88 Correct 1 ms 384 KB Output is correct
89 Correct 1 ms 384 KB Output is correct
90 Correct 1 ms 384 KB Output is correct
91 Correct 1 ms 384 KB Output is correct
92 Correct 0 ms 384 KB Output is correct
93 Correct 1 ms 384 KB Output is correct
94 Correct 1 ms 384 KB Output is correct
95 Correct 1 ms 384 KB Output is correct
96 Correct 0 ms 384 KB Output is correct
97 Correct 2 ms 384 KB Output is correct
98 Correct 1 ms 384 KB Output is correct
99 Correct 1 ms 384 KB Output is correct
100 Correct 1 ms 384 KB Output is correct
101 Correct 1 ms 384 KB Output is correct
102 Correct 1 ms 384 KB Output is correct
103 Correct 0 ms 384 KB Output is correct
104 Correct 12 ms 1920 KB Output is correct
105 Correct 12 ms 1968 KB Output is correct
106 Correct 15 ms 1968 KB Output is correct
107 Correct 13 ms 1920 KB Output is correct
108 Correct 11 ms 1920 KB Output is correct
109 Correct 13 ms 1968 KB Output is correct
110 Correct 0 ms 384 KB Output is correct
111 Correct 0 ms 384 KB Output is correct
112 Correct 1 ms 384 KB Output is correct
113 Correct 0 ms 384 KB Output is correct
114 Correct 1 ms 384 KB Output is correct
115 Correct 0 ms 384 KB Output is correct
116 Correct 15 ms 1920 KB Output is correct
117 Correct 17 ms 1920 KB Output is correct
118 Correct 17 ms 1920 KB Output is correct
119 Correct 17 ms 1920 KB Output is correct
120 Correct 20 ms 2072 KB Output is correct
121 Correct 16 ms 1920 KB Output is correct
122 Correct 10 ms 1920 KB Output is correct
123 Correct 12 ms 1920 KB Output is correct
124 Correct 14 ms 1920 KB Output is correct
125 Correct 12 ms 1920 KB Output is correct
126 Correct 13 ms 1960 KB Output is correct
127 Correct 15 ms 1968 KB Output is correct
128 Correct 0 ms 384 KB Output is correct
129 Correct 766 ms 46852 KB Output is correct
130 Correct 707 ms 46956 KB Output is correct
131 Correct 816 ms 46908 KB Output is correct
132 Correct 799 ms 46828 KB Output is correct
133 Correct 777 ms 46856 KB Output is correct
134 Correct 795 ms 46828 KB Output is correct
135 Correct 1 ms 384 KB Output is correct
136 Correct 1 ms 384 KB Output is correct
137 Correct 1 ms 384 KB Output is correct
138 Correct 1 ms 384 KB Output is correct
139 Correct 0 ms 384 KB Output is correct
140 Correct 0 ms 384 KB Output is correct
141 Correct 1163 ms 46856 KB Output is correct
142 Correct 1032 ms 46812 KB Output is correct
143 Correct 1010 ms 46852 KB Output is correct
144 Correct 981 ms 46828 KB Output is correct
145 Correct 962 ms 46828 KB Output is correct
146 Correct 1002 ms 46832 KB Output is correct
147 Correct 702 ms 46828 KB Output is correct
148 Correct 711 ms 46996 KB Output is correct
149 Correct 721 ms 46828 KB Output is correct
150 Correct 328 ms 46852 KB Output is correct
151 Correct 284 ms 46828 KB Output is correct
152 Correct 794 ms 46832 KB Output is correct
153 Correct 587 ms 46828 KB Output is correct
154 Correct 508 ms 46828 KB Output is correct
155 Correct 699 ms 46828 KB Output is correct