Submission #997301

# Submission time Handle Problem Language Result Execution time Memory
997301 2024-06-12T03:22:40 Z LOLOLO Fuel Station (NOI20_fuelstation) C++17
100 / 100
372 ms 47012 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (ll)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())
 
const int N = 3e5 + 10;
ll seg[N * 4], laz[N * 4];

void push(int id) {
    ll t = laz[id];
    laz[id * 2] += t;
    laz[id * 2 + 1] += t;
    seg[id * 2] += t;
    seg[id * 2 + 1] += t;
    laz[id] = 0;
}

void upd(int id, int l, int r, int u, int v, ll add) {
    if (l > v || r < u)
        return;

    if (l >= u && r <= v) {
        seg[id] += add;
        laz[id] += add;
        return;
    } 

    push(id);
    int m = (l + r) / 2;
    upd(id * 2, l, m, u, v, add);
    upd(id * 2 + 1, m + 1, r, u, v, add);
    seg[id] = min(seg[id * 2], seg[id * 2 + 1]);
}

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

    int n, d;
    cin >> n >> d;
    vector <int> pos;

    vector < vector <int>> station;
    for (int i = 1; i <= n; i++) {
        int x, a, b;
        cin >> x >> a >> b;
        station.pb({b, x, a});
        pos.pb(x);
    }

    pos.pb(0);
    pos.pb(d);
    uniquev(pos);
    sort(all(station), greater <vector <int>> ());

    for (int i = 0; i < sz(pos); i++) {
        upd(1, 0, sz(pos) - 1, i, i, -pos[i]);
    }

    int ans = d;
    for (auto x : station) {
        int p = upper_bound(all(pos), x[1]) - pos.begin();
        upd(1, 0, sz(pos) - 1, p, sz(pos) - 1, x[2]);
        if (abs(seg[1]) <= x[0]) {
            ans = min(ans, (int)abs(seg[1]));
        }
    }

    cout << ans << '\n';
    return 0;

}
 
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 222 ms 31064 KB Output is correct
2 Correct 185 ms 30952 KB Output is correct
3 Correct 235 ms 31828 KB Output is correct
4 Correct 182 ms 30964 KB Output is correct
5 Correct 187 ms 30188 KB Output is correct
6 Correct 201 ms 30696 KB Output is correct
7 Correct 196 ms 30980 KB Output is correct
8 Correct 177 ms 30188 KB Output is correct
9 Correct 210 ms 32920 KB Output is correct
10 Correct 186 ms 29932 KB Output is correct
11 Correct 197 ms 30192 KB Output is correct
12 Correct 178 ms 29728 KB Output is correct
13 Correct 189 ms 31212 KB Output is correct
14 Correct 204 ms 31728 KB Output is correct
15 Correct 180 ms 30868 KB Output is correct
16 Correct 203 ms 31464 KB Output is correct
17 Correct 185 ms 31704 KB Output is correct
18 Correct 191 ms 31984 KB Output is correct
19 Correct 182 ms 31408 KB Output is correct
20 Correct 196 ms 32232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 5 ms 3224 KB Output is correct
3 Correct 8 ms 5272 KB Output is correct
4 Correct 8 ms 5272 KB Output is correct
5 Correct 8 ms 5272 KB Output is correct
6 Correct 7 ms 5308 KB Output is correct
7 Correct 8 ms 5272 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 6 ms 3236 KB Output is correct
15 Correct 6 ms 3224 KB Output is correct
16 Correct 7 ms 3224 KB Output is correct
17 Correct 8 ms 3348 KB Output is correct
18 Correct 8 ms 3220 KB Output is correct
19 Correct 5 ms 3224 KB Output is correct
20 Correct 7 ms 3224 KB Output is correct
21 Correct 6 ms 3224 KB Output is correct
22 Correct 5 ms 3224 KB Output is correct
23 Correct 5 ms 3224 KB Output is correct
24 Correct 5 ms 3224 KB Output is correct
25 Correct 6 ms 3476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 5 ms 3224 KB Output is correct
3 Correct 8 ms 5272 KB Output is correct
4 Correct 8 ms 5272 KB Output is correct
5 Correct 8 ms 5272 KB Output is correct
6 Correct 7 ms 5308 KB Output is correct
7 Correct 8 ms 5272 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 6 ms 3236 KB Output is correct
15 Correct 6 ms 3224 KB Output is correct
16 Correct 7 ms 3224 KB Output is correct
17 Correct 8 ms 3348 KB Output is correct
18 Correct 8 ms 3220 KB Output is correct
19 Correct 5 ms 3224 KB Output is correct
20 Correct 7 ms 3224 KB Output is correct
21 Correct 6 ms 3224 KB Output is correct
22 Correct 5 ms 3224 KB Output is correct
23 Correct 5 ms 3224 KB Output is correct
24 Correct 5 ms 3224 KB Output is correct
25 Correct 6 ms 3476 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 164 ms 27220 KB Output is correct
28 Correct 196 ms 29080 KB Output is correct
29 Correct 206 ms 26872 KB Output is correct
30 Correct 221 ms 27884 KB Output is correct
31 Correct 200 ms 27124 KB Output is correct
32 Correct 216 ms 27388 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 0 ms 2396 KB Output is correct
37 Correct 0 ms 2396 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Correct 164 ms 26868 KB Output is correct
40 Correct 172 ms 26616 KB Output is correct
41 Correct 172 ms 26872 KB Output is correct
42 Correct 162 ms 27900 KB Output is correct
43 Correct 195 ms 26060 KB Output is correct
44 Correct 172 ms 25856 KB Output is correct
45 Correct 171 ms 28144 KB Output is correct
46 Correct 178 ms 27300 KB Output is correct
47 Correct 172 ms 27884 KB Output is correct
48 Correct 167 ms 28252 KB Output is correct
49 Correct 177 ms 26876 KB Output is correct
50 Correct 160 ms 25848 KB Output is correct
51 Correct 185 ms 26744 KB Output is correct
52 Correct 154 ms 26060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2512 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 0 ms 2396 KB Output is correct
28 Correct 0 ms 2396 KB Output is correct
29 Correct 0 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 5 ms 3224 KB Output is correct
18 Correct 8 ms 5272 KB Output is correct
19 Correct 8 ms 5272 KB Output is correct
20 Correct 8 ms 5272 KB Output is correct
21 Correct 7 ms 5308 KB Output is correct
22 Correct 8 ms 5272 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 0 ms 2396 KB Output is correct
28 Correct 0 ms 2396 KB Output is correct
29 Correct 6 ms 3236 KB Output is correct
30 Correct 6 ms 3224 KB Output is correct
31 Correct 7 ms 3224 KB Output is correct
32 Correct 8 ms 3348 KB Output is correct
33 Correct 8 ms 3220 KB Output is correct
34 Correct 5 ms 3224 KB Output is correct
35 Correct 7 ms 3224 KB Output is correct
36 Correct 6 ms 3224 KB Output is correct
37 Correct 5 ms 3224 KB Output is correct
38 Correct 5 ms 3224 KB Output is correct
39 Correct 5 ms 3224 KB Output is correct
40 Correct 6 ms 3476 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 5 ms 3352 KB Output is correct
43 Correct 8 ms 5524 KB Output is correct
44 Correct 8 ms 5560 KB Output is correct
45 Correct 9 ms 5524 KB Output is correct
46 Correct 8 ms 5528 KB Output is correct
47 Correct 9 ms 5528 KB Output is correct
48 Correct 0 ms 2396 KB Output is correct
49 Correct 0 ms 2396 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 0 ms 2396 KB Output is correct
52 Correct 0 ms 2396 KB Output is correct
53 Correct 1 ms 2396 KB Output is correct
54 Correct 9 ms 5528 KB Output is correct
55 Correct 8 ms 5528 KB Output is correct
56 Correct 8 ms 5480 KB Output is correct
57 Correct 8 ms 5524 KB Output is correct
58 Correct 8 ms 5528 KB Output is correct
59 Correct 5 ms 3224 KB Output is correct
60 Correct 6 ms 3224 KB Output is correct
61 Correct 6 ms 3224 KB Output is correct
62 Correct 6 ms 3224 KB Output is correct
63 Correct 6 ms 3220 KB Output is correct
64 Correct 7 ms 3224 KB Output is correct
65 Correct 7 ms 3192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 222 ms 31064 KB Output is correct
17 Correct 185 ms 30952 KB Output is correct
18 Correct 235 ms 31828 KB Output is correct
19 Correct 182 ms 30964 KB Output is correct
20 Correct 187 ms 30188 KB Output is correct
21 Correct 201 ms 30696 KB Output is correct
22 Correct 196 ms 30980 KB Output is correct
23 Correct 177 ms 30188 KB Output is correct
24 Correct 210 ms 32920 KB Output is correct
25 Correct 186 ms 29932 KB Output is correct
26 Correct 197 ms 30192 KB Output is correct
27 Correct 178 ms 29728 KB Output is correct
28 Correct 189 ms 31212 KB Output is correct
29 Correct 204 ms 31728 KB Output is correct
30 Correct 180 ms 30868 KB Output is correct
31 Correct 203 ms 31464 KB Output is correct
32 Correct 185 ms 31704 KB Output is correct
33 Correct 191 ms 31984 KB Output is correct
34 Correct 182 ms 31408 KB Output is correct
35 Correct 196 ms 32232 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 5 ms 3224 KB Output is correct
38 Correct 8 ms 5272 KB Output is correct
39 Correct 8 ms 5272 KB Output is correct
40 Correct 8 ms 5272 KB Output is correct
41 Correct 7 ms 5308 KB Output is correct
42 Correct 8 ms 5272 KB Output is correct
43 Correct 0 ms 2396 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 0 ms 2396 KB Output is correct
46 Correct 0 ms 2396 KB Output is correct
47 Correct 0 ms 2396 KB Output is correct
48 Correct 0 ms 2396 KB Output is correct
49 Correct 6 ms 3236 KB Output is correct
50 Correct 6 ms 3224 KB Output is correct
51 Correct 7 ms 3224 KB Output is correct
52 Correct 8 ms 3348 KB Output is correct
53 Correct 8 ms 3220 KB Output is correct
54 Correct 5 ms 3224 KB Output is correct
55 Correct 7 ms 3224 KB Output is correct
56 Correct 6 ms 3224 KB Output is correct
57 Correct 5 ms 3224 KB Output is correct
58 Correct 5 ms 3224 KB Output is correct
59 Correct 5 ms 3224 KB Output is correct
60 Correct 6 ms 3476 KB Output is correct
61 Correct 0 ms 2396 KB Output is correct
62 Correct 164 ms 27220 KB Output is correct
63 Correct 196 ms 29080 KB Output is correct
64 Correct 206 ms 26872 KB Output is correct
65 Correct 221 ms 27884 KB Output is correct
66 Correct 200 ms 27124 KB Output is correct
67 Correct 216 ms 27388 KB Output is correct
68 Correct 1 ms 2396 KB Output is correct
69 Correct 0 ms 2396 KB Output is correct
70 Correct 1 ms 2396 KB Output is correct
71 Correct 0 ms 2396 KB Output is correct
72 Correct 0 ms 2396 KB Output is correct
73 Correct 0 ms 2396 KB Output is correct
74 Correct 164 ms 26868 KB Output is correct
75 Correct 172 ms 26616 KB Output is correct
76 Correct 172 ms 26872 KB Output is correct
77 Correct 162 ms 27900 KB Output is correct
78 Correct 195 ms 26060 KB Output is correct
79 Correct 172 ms 25856 KB Output is correct
80 Correct 171 ms 28144 KB Output is correct
81 Correct 178 ms 27300 KB Output is correct
82 Correct 172 ms 27884 KB Output is correct
83 Correct 167 ms 28252 KB Output is correct
84 Correct 177 ms 26876 KB Output is correct
85 Correct 160 ms 25848 KB Output is correct
86 Correct 185 ms 26744 KB Output is correct
87 Correct 154 ms 26060 KB Output is correct
88 Correct 1 ms 2396 KB Output is correct
89 Correct 0 ms 2396 KB Output is correct
90 Correct 1 ms 2396 KB Output is correct
91 Correct 0 ms 2396 KB Output is correct
92 Correct 0 ms 2512 KB Output is correct
93 Correct 1 ms 2396 KB Output is correct
94 Correct 1 ms 2396 KB Output is correct
95 Correct 1 ms 2396 KB Output is correct
96 Correct 0 ms 2396 KB Output is correct
97 Correct 0 ms 2396 KB Output is correct
98 Correct 0 ms 2396 KB Output is correct
99 Correct 0 ms 2396 KB Output is correct
100 Correct 0 ms 2396 KB Output is correct
101 Correct 0 ms 2396 KB Output is correct
102 Correct 1 ms 2396 KB Output is correct
103 Correct 1 ms 2396 KB Output is correct
104 Correct 5 ms 3352 KB Output is correct
105 Correct 8 ms 5524 KB Output is correct
106 Correct 8 ms 5560 KB Output is correct
107 Correct 9 ms 5524 KB Output is correct
108 Correct 8 ms 5528 KB Output is correct
109 Correct 9 ms 5528 KB Output is correct
110 Correct 0 ms 2396 KB Output is correct
111 Correct 0 ms 2396 KB Output is correct
112 Correct 1 ms 2396 KB Output is correct
113 Correct 0 ms 2396 KB Output is correct
114 Correct 0 ms 2396 KB Output is correct
115 Correct 1 ms 2396 KB Output is correct
116 Correct 9 ms 5528 KB Output is correct
117 Correct 8 ms 5528 KB Output is correct
118 Correct 8 ms 5480 KB Output is correct
119 Correct 8 ms 5524 KB Output is correct
120 Correct 8 ms 5528 KB Output is correct
121 Correct 5 ms 3224 KB Output is correct
122 Correct 6 ms 3224 KB Output is correct
123 Correct 6 ms 3224 KB Output is correct
124 Correct 6 ms 3224 KB Output is correct
125 Correct 6 ms 3220 KB Output is correct
126 Correct 7 ms 3224 KB Output is correct
127 Correct 7 ms 3192 KB Output is correct
128 Correct 1 ms 2396 KB Output is correct
129 Correct 268 ms 30960 KB Output is correct
130 Correct 337 ms 45032 KB Output is correct
131 Correct 372 ms 46832 KB Output is correct
132 Correct 306 ms 45008 KB Output is correct
133 Correct 334 ms 45668 KB Output is correct
134 Correct 332 ms 45452 KB Output is correct
135 Correct 1 ms 2396 KB Output is correct
136 Correct 0 ms 2396 KB Output is correct
137 Correct 1 ms 2904 KB Output is correct
138 Correct 0 ms 2396 KB Output is correct
139 Correct 1 ms 2396 KB Output is correct
140 Correct 1 ms 2396 KB Output is correct
141 Correct 306 ms 46516 KB Output is correct
142 Correct 326 ms 46064 KB Output is correct
143 Correct 330 ms 45464 KB Output is correct
144 Correct 370 ms 47012 KB Output is correct
145 Correct 333 ms 45544 KB Output is correct
146 Correct 314 ms 44520 KB Output is correct
147 Correct 299 ms 44500 KB Output is correct
148 Correct 307 ms 44236 KB Output is correct
149 Correct 227 ms 31588 KB Output is correct
150 Correct 188 ms 31224 KB Output is correct
151 Correct 171 ms 30316 KB Output is correct
152 Correct 225 ms 32236 KB Output is correct
153 Correct 185 ms 30448 KB Output is correct
154 Correct 179 ms 29460 KB Output is correct
155 Correct 231 ms 31480 KB Output is correct