답안 #337595

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
337595 2020-12-21T07:40:54 Z ncduy0303 Fuel Station (NOI20_fuelstation) C++17
100 / 100
547 ms 33004 KB
#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e5 + 1;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;

struct segtree { 
    struct tdata {
        ll mn, addval;
        tdata(): mn(), addval() {}
        tdata(ll val): mn(val), addval() {}
        tdata(tdata l, tdata r): mn(min(l.mn, r.mn)), addval() {}
    };
    int ln(int node) {return 2 * node;}
    int rn(int node) {return 2 * node + 1;}
    int n; vector<tdata> st;
    segtree(int n): n(n), st(4 * n) {}
    void apply(int node, int start, int end, ll val) {
        st[node].mn += val;
        st[node].addval += val;
    }
    void combine(int node) {
        st[node].mn = min(st[ln(node)].mn, st[rn(node)].mn);
    }
    void propagate(int node, int start, int end) {
        if (start == end || st[node].addval == 0) return;
        int mid = (start + end) / 2;
        apply(ln(node), start, mid, st[node].addval);
        apply(rn(node), mid + 1, end, st[node].addval);
        st[node].addval = 0;
    }
    void update(int node, int start, int end, int l, int r, ll val) {
        propagate(node, start, end);
        if (r < start || end < l) return;
        if (l <= start && end <= r) {
            apply(node, start, end, val);
            return;
        }
        int mid = (start + end) / 2;
        update(ln(node), start, mid, l, r, val);
        update(rn(node), mid + 1, end, l, r, val);
        combine(node);
    }
    tdata query(int node, int start, int end, int l, int r) {
        propagate(node, start, end);
        if (r < start || end < l) return tdata();
        if (l <= start && end <= r) return st[node];
        int mid = (start + end) / 2;
        return tdata(query(ln(node), start, mid, l, r), query(rn(node), mid + 1, end, l, r));
    }
    void update(int l, int r, ll val) {update(1, 0, n - 1, l, r, val);}
    tdata query(int l, int r) {return query(1, 0, n - 1, l, r);}
};

void solve() {
    int n, d; cin >> n >> d;
    vector<ar<int,3>> arr(n + 1); // {b, x, a}
    vector<int> pos(n + 1);
    for (int i = 0; i < n; i++) {
        int x, a, b; cin >> x >> a >> b;
        arr[i] = {b, x, a};
        pos[i] = x;
    }
    arr[n] = {d, d, 0};
    pos[n] = d;
    sort(arr.rbegin(), arr.rend());
    sort(pos.begin(), pos.end());
    segtree st(n + 1);
    for (int i = 0; i <= n; i++) {
        st.update(i, i, -pos[i]);
    }
    ll ans = INF, b_pre = 0;
    for (auto [b, x, a] : arr) {
        st.update(0, n, b - b_pre);
        int idx = lower_bound(pos.begin(), pos.end(), x) - pos.begin();
        if (idx < n) st.update(idx + 1, n, a);
        ll left = st.query(0, n).mn;
        if (left >= 0) ans = min(ans, b - left);
        b_pre = b;
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int tc = 1;
    // cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 520 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 384 ms 32264 KB Output is correct
2 Correct 386 ms 32236 KB Output is correct
3 Correct 382 ms 32236 KB Output is correct
4 Correct 376 ms 32236 KB Output is correct
5 Correct 373 ms 32876 KB Output is correct
6 Correct 380 ms 31596 KB Output is correct
7 Correct 382 ms 31724 KB Output is correct
8 Correct 368 ms 32364 KB Output is correct
9 Correct 382 ms 33004 KB Output is correct
10 Correct 370 ms 31596 KB Output is correct
11 Correct 381 ms 31724 KB Output is correct
12 Correct 374 ms 32364 KB Output is correct
13 Correct 381 ms 31724 KB Output is correct
14 Correct 382 ms 32252 KB Output is correct
15 Correct 370 ms 32236 KB Output is correct
16 Correct 386 ms 32876 KB Output is correct
17 Correct 376 ms 33004 KB Output is correct
18 Correct 380 ms 32236 KB Output is correct
19 Correct 374 ms 32364 KB Output is correct
20 Correct 383 ms 32364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 10 ms 1260 KB Output is correct
3 Correct 14 ms 1260 KB Output is correct
4 Correct 11 ms 1260 KB Output is correct
5 Correct 11 ms 1260 KB Output is correct
6 Correct 11 ms 1260 KB Output is correct
7 Correct 11 ms 1260 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 11 ms 1260 KB Output is correct
15 Correct 11 ms 1260 KB Output is correct
16 Correct 11 ms 1260 KB Output is correct
17 Correct 11 ms 1260 KB Output is correct
18 Correct 11 ms 1260 KB Output is correct
19 Correct 10 ms 1260 KB Output is correct
20 Correct 11 ms 1260 KB Output is correct
21 Correct 11 ms 1260 KB Output is correct
22 Correct 10 ms 1260 KB Output is correct
23 Correct 10 ms 1132 KB Output is correct
24 Correct 10 ms 1260 KB Output is correct
25 Correct 10 ms 1260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 10 ms 1260 KB Output is correct
3 Correct 14 ms 1260 KB Output is correct
4 Correct 11 ms 1260 KB Output is correct
5 Correct 11 ms 1260 KB Output is correct
6 Correct 11 ms 1260 KB Output is correct
7 Correct 11 ms 1260 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 11 ms 1260 KB Output is correct
15 Correct 11 ms 1260 KB Output is correct
16 Correct 11 ms 1260 KB Output is correct
17 Correct 11 ms 1260 KB Output is correct
18 Correct 11 ms 1260 KB Output is correct
19 Correct 10 ms 1260 KB Output is correct
20 Correct 11 ms 1260 KB Output is correct
21 Correct 11 ms 1260 KB Output is correct
22 Correct 10 ms 1260 KB Output is correct
23 Correct 10 ms 1132 KB Output is correct
24 Correct 10 ms 1260 KB Output is correct
25 Correct 10 ms 1260 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 406 ms 28240 KB Output is correct
28 Correct 473 ms 28012 KB Output is correct
29 Correct 466 ms 27756 KB Output is correct
30 Correct 467 ms 27756 KB Output is correct
31 Correct 494 ms 28140 KB Output is correct
32 Correct 483 ms 28012 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 434 ms 28140 KB Output is correct
40 Correct 437 ms 28268 KB Output is correct
41 Correct 456 ms 28140 KB Output is correct
42 Correct 428 ms 28248 KB Output is correct
43 Correct 492 ms 28188 KB Output is correct
44 Correct 404 ms 27628 KB Output is correct
45 Correct 341 ms 27500 KB Output is correct
46 Correct 438 ms 28140 KB Output is correct
47 Correct 362 ms 29836 KB Output is correct
48 Correct 356 ms 29676 KB Output is correct
49 Correct 421 ms 27628 KB Output is correct
50 Correct 395 ms 28012 KB Output is correct
51 Correct 408 ms 27892 KB Output is correct
52 Correct 400 ms 27756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 520 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 520 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 10 ms 1260 KB Output is correct
18 Correct 14 ms 1260 KB Output is correct
19 Correct 11 ms 1260 KB Output is correct
20 Correct 11 ms 1260 KB Output is correct
21 Correct 11 ms 1260 KB Output is correct
22 Correct 11 ms 1260 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 11 ms 1260 KB Output is correct
30 Correct 11 ms 1260 KB Output is correct
31 Correct 11 ms 1260 KB Output is correct
32 Correct 11 ms 1260 KB Output is correct
33 Correct 11 ms 1260 KB Output is correct
34 Correct 10 ms 1260 KB Output is correct
35 Correct 11 ms 1260 KB Output is correct
36 Correct 11 ms 1260 KB Output is correct
37 Correct 10 ms 1260 KB Output is correct
38 Correct 10 ms 1132 KB Output is correct
39 Correct 10 ms 1260 KB Output is correct
40 Correct 10 ms 1260 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 11 ms 1388 KB Output is correct
43 Correct 12 ms 1388 KB Output is correct
44 Correct 12 ms 1388 KB Output is correct
45 Correct 12 ms 1516 KB Output is correct
46 Correct 12 ms 1388 KB Output is correct
47 Correct 12 ms 1388 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 1 ms 364 KB Output is correct
50 Correct 1 ms 364 KB Output is correct
51 Correct 1 ms 364 KB Output is correct
52 Correct 1 ms 364 KB Output is correct
53 Correct 1 ms 364 KB Output is correct
54 Correct 12 ms 1388 KB Output is correct
55 Correct 12 ms 1388 KB Output is correct
56 Correct 12 ms 1388 KB Output is correct
57 Correct 12 ms 1388 KB Output is correct
58 Correct 12 ms 1388 KB Output is correct
59 Correct 11 ms 1388 KB Output is correct
60 Correct 11 ms 1388 KB Output is correct
61 Correct 11 ms 1388 KB Output is correct
62 Correct 12 ms 1388 KB Output is correct
63 Correct 12 ms 1388 KB Output is correct
64 Correct 12 ms 1388 KB Output is correct
65 Correct 11 ms 1388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 520 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 384 ms 32264 KB Output is correct
17 Correct 386 ms 32236 KB Output is correct
18 Correct 382 ms 32236 KB Output is correct
19 Correct 376 ms 32236 KB Output is correct
20 Correct 373 ms 32876 KB Output is correct
21 Correct 380 ms 31596 KB Output is correct
22 Correct 382 ms 31724 KB Output is correct
23 Correct 368 ms 32364 KB Output is correct
24 Correct 382 ms 33004 KB Output is correct
25 Correct 370 ms 31596 KB Output is correct
26 Correct 381 ms 31724 KB Output is correct
27 Correct 374 ms 32364 KB Output is correct
28 Correct 381 ms 31724 KB Output is correct
29 Correct 382 ms 32252 KB Output is correct
30 Correct 370 ms 32236 KB Output is correct
31 Correct 386 ms 32876 KB Output is correct
32 Correct 376 ms 33004 KB Output is correct
33 Correct 380 ms 32236 KB Output is correct
34 Correct 374 ms 32364 KB Output is correct
35 Correct 383 ms 32364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 10 ms 1260 KB Output is correct
38 Correct 14 ms 1260 KB Output is correct
39 Correct 11 ms 1260 KB Output is correct
40 Correct 11 ms 1260 KB Output is correct
41 Correct 11 ms 1260 KB Output is correct
42 Correct 11 ms 1260 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 11 ms 1260 KB Output is correct
50 Correct 11 ms 1260 KB Output is correct
51 Correct 11 ms 1260 KB Output is correct
52 Correct 11 ms 1260 KB Output is correct
53 Correct 11 ms 1260 KB Output is correct
54 Correct 10 ms 1260 KB Output is correct
55 Correct 11 ms 1260 KB Output is correct
56 Correct 11 ms 1260 KB Output is correct
57 Correct 10 ms 1260 KB Output is correct
58 Correct 10 ms 1132 KB Output is correct
59 Correct 10 ms 1260 KB Output is correct
60 Correct 10 ms 1260 KB Output is correct
61 Correct 1 ms 364 KB Output is correct
62 Correct 406 ms 28240 KB Output is correct
63 Correct 473 ms 28012 KB Output is correct
64 Correct 466 ms 27756 KB Output is correct
65 Correct 467 ms 27756 KB Output is correct
66 Correct 494 ms 28140 KB Output is correct
67 Correct 483 ms 28012 KB Output is correct
68 Correct 1 ms 364 KB Output is correct
69 Correct 1 ms 364 KB Output is correct
70 Correct 1 ms 364 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 1 ms 364 KB Output is correct
73 Correct 1 ms 364 KB Output is correct
74 Correct 434 ms 28140 KB Output is correct
75 Correct 437 ms 28268 KB Output is correct
76 Correct 456 ms 28140 KB Output is correct
77 Correct 428 ms 28248 KB Output is correct
78 Correct 492 ms 28188 KB Output is correct
79 Correct 404 ms 27628 KB Output is correct
80 Correct 341 ms 27500 KB Output is correct
81 Correct 438 ms 28140 KB Output is correct
82 Correct 362 ms 29836 KB Output is correct
83 Correct 356 ms 29676 KB Output is correct
84 Correct 421 ms 27628 KB Output is correct
85 Correct 395 ms 28012 KB Output is correct
86 Correct 408 ms 27892 KB Output is correct
87 Correct 400 ms 27756 KB Output is correct
88 Correct 1 ms 364 KB Output is correct
89 Correct 1 ms 364 KB Output is correct
90 Correct 1 ms 364 KB Output is correct
91 Correct 1 ms 364 KB Output is correct
92 Correct 1 ms 364 KB Output is correct
93 Correct 1 ms 364 KB Output is correct
94 Correct 1 ms 364 KB Output is correct
95 Correct 1 ms 364 KB Output is correct
96 Correct 1 ms 364 KB Output is correct
97 Correct 1 ms 364 KB Output is correct
98 Correct 1 ms 364 KB Output is correct
99 Correct 1 ms 364 KB Output is correct
100 Correct 1 ms 364 KB Output is correct
101 Correct 1 ms 364 KB Output is correct
102 Correct 1 ms 364 KB Output is correct
103 Correct 1 ms 364 KB Output is correct
104 Correct 11 ms 1388 KB Output is correct
105 Correct 12 ms 1388 KB Output is correct
106 Correct 12 ms 1388 KB Output is correct
107 Correct 12 ms 1516 KB Output is correct
108 Correct 12 ms 1388 KB Output is correct
109 Correct 12 ms 1388 KB Output is correct
110 Correct 1 ms 364 KB Output is correct
111 Correct 1 ms 364 KB Output is correct
112 Correct 1 ms 364 KB Output is correct
113 Correct 1 ms 364 KB Output is correct
114 Correct 1 ms 364 KB Output is correct
115 Correct 1 ms 364 KB Output is correct
116 Correct 12 ms 1388 KB Output is correct
117 Correct 12 ms 1388 KB Output is correct
118 Correct 12 ms 1388 KB Output is correct
119 Correct 12 ms 1388 KB Output is correct
120 Correct 12 ms 1388 KB Output is correct
121 Correct 11 ms 1388 KB Output is correct
122 Correct 11 ms 1388 KB Output is correct
123 Correct 11 ms 1388 KB Output is correct
124 Correct 12 ms 1388 KB Output is correct
125 Correct 12 ms 1388 KB Output is correct
126 Correct 12 ms 1388 KB Output is correct
127 Correct 11 ms 1388 KB Output is correct
128 Correct 1 ms 364 KB Output is correct
129 Correct 527 ms 31416 KB Output is correct
130 Correct 528 ms 31980 KB Output is correct
131 Correct 530 ms 32620 KB Output is correct
132 Correct 530 ms 32108 KB Output is correct
133 Correct 523 ms 31980 KB Output is correct
134 Correct 534 ms 32620 KB Output is correct
135 Correct 1 ms 364 KB Output is correct
136 Correct 1 ms 364 KB Output is correct
137 Correct 1 ms 364 KB Output is correct
138 Correct 1 ms 364 KB Output is correct
139 Correct 1 ms 364 KB Output is correct
140 Correct 1 ms 364 KB Output is correct
141 Correct 542 ms 32748 KB Output is correct
142 Correct 531 ms 32364 KB Output is correct
143 Correct 547 ms 32620 KB Output is correct
144 Correct 545 ms 32492 KB Output is correct
145 Correct 530 ms 32748 KB Output is correct
146 Correct 488 ms 30828 KB Output is correct
147 Correct 492 ms 31724 KB Output is correct
148 Correct 475 ms 31212 KB Output is correct
149 Correct 532 ms 32076 KB Output is correct
150 Correct 370 ms 32364 KB Output is correct
151 Correct 375 ms 32236 KB Output is correct
152 Correct 490 ms 31980 KB Output is correct
153 Correct 462 ms 31980 KB Output is correct
154 Correct 438 ms 31968 KB Output is correct
155 Correct 530 ms 31980 KB Output is correct