Submission #1106026

# Submission time Handle Problem Language Result Execution time Memory
1106026 2024-10-29T01:48:37 Z HiepVu217 Fuel Station (NOI20_fuelstation) C++17
100 / 100
249 ms 29512 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 17;
int n, d;
long long st[4 * N], lz[4 * N], ans;
bool t;
struct dta
{
    int x, a, b, id;
    bool operator < (const dta& other) const {
        return (t ? b > other.b : x < other.x);
    }
} fuel[N];
void down (int id)
{
    st[id * 2] += lz[id];
    lz[id * 2] += lz[id];
    st[id * 2 + 1] += lz[id];
    lz[id * 2 + 1] += lz[id];
    lz[id] = 0;
}
void update (int id, int l, int r, int u, int v, int x)
{
    if (v < l || r < u)
    {
        return;
    }
    if (u <= l && r <= v)
    {
        st[id] += x, lz[id] += x;
        return;
    }
    int mid = l + r >> 1;
    down(id);
    update (id * 2, l, mid, u, v, x);
    update (id * 2 + 1, mid + 1, r, u, v, x);
    st[id] = max (st[id * 2], st[id * 2 + 1]);
}
long long get (int id, int l, int r, int u, int v)
{
    if (v < l || r < u)
    {
        return 0;
    }
    if (u <= l && r <= v)
    {
        return st[id];
    }
    int mid = l + r >> 1;
    down(id);
    return max (get (id * 2, l, mid, u, v), get (id * 2 + 1, mid + 1, r, u, v));
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> d;
    for (int i = 1, x, a, b; i <= n; ++i)
    {
        cin >> x >> a >> b;
        fuel[i] = {x, a, b, 0};
    }
    sort (fuel + 1, fuel + n + 1);
    fuel[n + 1] = {d, 0, 0};
    for (int i = 1; i <= n + 1; ++i)
    {
        fuel[i].id = i;
        update (1, 1, n + 1, i, i, fuel[i].x);
    }
    t = 1;
    sort (fuel + 1, fuel + n + 1);
    ans = st[1];
    for (int i = 1; i <= n + 1; ++i)
    {
        auto [x, a, b, id] = fuel[i];
        update (1, 1, n + 1, id + 1, n + 1, -a);
        if (st[1] <= b)
        {
            ans = min (ans, st[1]);
        }
    }
    cout << ans;
}

Compilation message

FuelStation.cpp: In function 'void update(int, int, int, int, int, int)':
FuelStation.cpp:33:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   33 |     int mid = l + r >> 1;
      |               ~~^~~
FuelStation.cpp: In function 'long long int get(int, int, int, int, int)':
FuelStation.cpp:49:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 |     int mid = l + r >> 1;
      |               ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 179 ms 27472 KB Output is correct
2 Correct 182 ms 23168 KB Output is correct
3 Correct 175 ms 23164 KB Output is correct
4 Correct 172 ms 27464 KB Output is correct
5 Correct 175 ms 23164 KB Output is correct
6 Correct 177 ms 23172 KB Output is correct
7 Correct 182 ms 23112 KB Output is correct
8 Correct 169 ms 23160 KB Output is correct
9 Correct 180 ms 23160 KB Output is correct
10 Correct 187 ms 23112 KB Output is correct
11 Correct 187 ms 23172 KB Output is correct
12 Correct 181 ms 23164 KB Output is correct
13 Correct 200 ms 23124 KB Output is correct
14 Correct 187 ms 23112 KB Output is correct
15 Correct 187 ms 23112 KB Output is correct
16 Correct 202 ms 27808 KB Output is correct
17 Correct 190 ms 23168 KB Output is correct
18 Correct 185 ms 23120 KB Output is correct
19 Correct 180 ms 23112 KB Output is correct
20 Correct 201 ms 27476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 7 ms 2896 KB Output is correct
3 Correct 7 ms 2896 KB Output is correct
4 Correct 6 ms 2944 KB Output is correct
5 Correct 7 ms 3064 KB Output is correct
6 Correct 7 ms 2896 KB Output is correct
7 Correct 7 ms 2932 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 6 ms 2896 KB Output is correct
15 Correct 7 ms 2896 KB Output is correct
16 Correct 6 ms 2924 KB Output is correct
17 Correct 7 ms 2896 KB Output is correct
18 Correct 6 ms 2896 KB Output is correct
19 Correct 7 ms 2896 KB Output is correct
20 Correct 6 ms 2896 KB Output is correct
21 Correct 6 ms 2896 KB Output is correct
22 Correct 6 ms 2920 KB Output is correct
23 Correct 6 ms 2896 KB Output is correct
24 Correct 7 ms 2896 KB Output is correct
25 Correct 6 ms 2932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 7 ms 2896 KB Output is correct
3 Correct 7 ms 2896 KB Output is correct
4 Correct 6 ms 2944 KB Output is correct
5 Correct 7 ms 3064 KB Output is correct
6 Correct 7 ms 2896 KB Output is correct
7 Correct 7 ms 2932 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 6 ms 2896 KB Output is correct
15 Correct 7 ms 2896 KB Output is correct
16 Correct 6 ms 2924 KB Output is correct
17 Correct 7 ms 2896 KB Output is correct
18 Correct 6 ms 2896 KB Output is correct
19 Correct 7 ms 2896 KB Output is correct
20 Correct 6 ms 2896 KB Output is correct
21 Correct 6 ms 2896 KB Output is correct
22 Correct 6 ms 2920 KB Output is correct
23 Correct 6 ms 2896 KB Output is correct
24 Correct 7 ms 2896 KB Output is correct
25 Correct 6 ms 2932 KB Output is correct
26 Correct 1 ms 2384 KB Output is correct
27 Correct 205 ms 23200 KB Output is correct
28 Correct 187 ms 25288 KB Output is correct
29 Correct 193 ms 25160 KB Output is correct
30 Correct 192 ms 23112 KB Output is correct
31 Correct 205 ms 23116 KB Output is correct
32 Correct 188 ms 24648 KB Output is correct
33 Correct 1 ms 2384 KB Output is correct
34 Correct 1 ms 2384 KB Output is correct
35 Correct 1 ms 2384 KB Output is correct
36 Correct 1 ms 2384 KB Output is correct
37 Correct 1 ms 2384 KB Output is correct
38 Correct 1 ms 2556 KB Output is correct
39 Correct 204 ms 25448 KB Output is correct
40 Correct 212 ms 23112 KB Output is correct
41 Correct 198 ms 23172 KB Output is correct
42 Correct 215 ms 23200 KB Output is correct
43 Correct 206 ms 25416 KB Output is correct
44 Correct 175 ms 25160 KB Output is correct
45 Correct 167 ms 25160 KB Output is correct
46 Correct 186 ms 23164 KB Output is correct
47 Correct 160 ms 26236 KB Output is correct
48 Correct 161 ms 26184 KB Output is correct
49 Correct 191 ms 23112 KB Output is correct
50 Correct 181 ms 25416 KB Output is correct
51 Correct 185 ms 25400 KB Output is correct
52 Correct 181 ms 23112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2556 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 1 ms 2384 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2552 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2384 KB Output is correct
22 Correct 1 ms 2384 KB Output is correct
23 Correct 1 ms 2552 KB Output is correct
24 Correct 1 ms 2384 KB Output is correct
25 Correct 1 ms 2384 KB Output is correct
26 Correct 1 ms 2384 KB Output is correct
27 Correct 1 ms 2384 KB Output is correct
28 Correct 1 ms 2384 KB Output is correct
29 Correct 1 ms 2384 KB Output is correct
30 Correct 1 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2556 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 7 ms 2896 KB Output is correct
18 Correct 7 ms 2896 KB Output is correct
19 Correct 6 ms 2944 KB Output is correct
20 Correct 7 ms 3064 KB Output is correct
21 Correct 7 ms 2896 KB Output is correct
22 Correct 7 ms 2932 KB Output is correct
23 Correct 1 ms 2384 KB Output is correct
24 Correct 1 ms 2384 KB Output is correct
25 Correct 1 ms 2384 KB Output is correct
26 Correct 1 ms 2384 KB Output is correct
27 Correct 1 ms 2384 KB Output is correct
28 Correct 1 ms 2384 KB Output is correct
29 Correct 6 ms 2896 KB Output is correct
30 Correct 7 ms 2896 KB Output is correct
31 Correct 6 ms 2924 KB Output is correct
32 Correct 7 ms 2896 KB Output is correct
33 Correct 6 ms 2896 KB Output is correct
34 Correct 7 ms 2896 KB Output is correct
35 Correct 6 ms 2896 KB Output is correct
36 Correct 6 ms 2896 KB Output is correct
37 Correct 6 ms 2920 KB Output is correct
38 Correct 6 ms 2896 KB Output is correct
39 Correct 7 ms 2896 KB Output is correct
40 Correct 6 ms 2932 KB Output is correct
41 Correct 1 ms 2436 KB Output is correct
42 Correct 6 ms 2896 KB Output is correct
43 Correct 8 ms 2896 KB Output is correct
44 Correct 8 ms 2796 KB Output is correct
45 Correct 8 ms 2896 KB Output is correct
46 Correct 7 ms 3152 KB Output is correct
47 Correct 7 ms 2896 KB Output is correct
48 Correct 1 ms 2384 KB Output is correct
49 Correct 1 ms 2384 KB Output is correct
50 Correct 1 ms 2384 KB Output is correct
51 Correct 1 ms 2384 KB Output is correct
52 Correct 1 ms 2384 KB Output is correct
53 Correct 1 ms 2384 KB Output is correct
54 Correct 7 ms 2896 KB Output is correct
55 Correct 7 ms 2896 KB Output is correct
56 Correct 7 ms 3152 KB Output is correct
57 Correct 8 ms 2896 KB Output is correct
58 Correct 8 ms 3152 KB Output is correct
59 Correct 7 ms 3152 KB Output is correct
60 Correct 7 ms 3152 KB Output is correct
61 Correct 7 ms 2936 KB Output is correct
62 Correct 8 ms 3152 KB Output is correct
63 Correct 7 ms 3152 KB Output is correct
64 Correct 7 ms 2896 KB Output is correct
65 Correct 7 ms 2896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2556 KB Output is correct
16 Correct 179 ms 27472 KB Output is correct
17 Correct 182 ms 23168 KB Output is correct
18 Correct 175 ms 23164 KB Output is correct
19 Correct 172 ms 27464 KB Output is correct
20 Correct 175 ms 23164 KB Output is correct
21 Correct 177 ms 23172 KB Output is correct
22 Correct 182 ms 23112 KB Output is correct
23 Correct 169 ms 23160 KB Output is correct
24 Correct 180 ms 23160 KB Output is correct
25 Correct 187 ms 23112 KB Output is correct
26 Correct 187 ms 23172 KB Output is correct
27 Correct 181 ms 23164 KB Output is correct
28 Correct 200 ms 23124 KB Output is correct
29 Correct 187 ms 23112 KB Output is correct
30 Correct 187 ms 23112 KB Output is correct
31 Correct 202 ms 27808 KB Output is correct
32 Correct 190 ms 23168 KB Output is correct
33 Correct 185 ms 23120 KB Output is correct
34 Correct 180 ms 23112 KB Output is correct
35 Correct 201 ms 27476 KB Output is correct
36 Correct 1 ms 2384 KB Output is correct
37 Correct 7 ms 2896 KB Output is correct
38 Correct 7 ms 2896 KB Output is correct
39 Correct 6 ms 2944 KB Output is correct
40 Correct 7 ms 3064 KB Output is correct
41 Correct 7 ms 2896 KB Output is correct
42 Correct 7 ms 2932 KB Output is correct
43 Correct 1 ms 2384 KB Output is correct
44 Correct 1 ms 2384 KB Output is correct
45 Correct 1 ms 2384 KB Output is correct
46 Correct 1 ms 2384 KB Output is correct
47 Correct 1 ms 2384 KB Output is correct
48 Correct 1 ms 2384 KB Output is correct
49 Correct 6 ms 2896 KB Output is correct
50 Correct 7 ms 2896 KB Output is correct
51 Correct 6 ms 2924 KB Output is correct
52 Correct 7 ms 2896 KB Output is correct
53 Correct 6 ms 2896 KB Output is correct
54 Correct 7 ms 2896 KB Output is correct
55 Correct 6 ms 2896 KB Output is correct
56 Correct 6 ms 2896 KB Output is correct
57 Correct 6 ms 2920 KB Output is correct
58 Correct 6 ms 2896 KB Output is correct
59 Correct 7 ms 2896 KB Output is correct
60 Correct 6 ms 2932 KB Output is correct
61 Correct 1 ms 2384 KB Output is correct
62 Correct 205 ms 23200 KB Output is correct
63 Correct 187 ms 25288 KB Output is correct
64 Correct 193 ms 25160 KB Output is correct
65 Correct 192 ms 23112 KB Output is correct
66 Correct 205 ms 23116 KB Output is correct
67 Correct 188 ms 24648 KB Output is correct
68 Correct 1 ms 2384 KB Output is correct
69 Correct 1 ms 2384 KB Output is correct
70 Correct 1 ms 2384 KB Output is correct
71 Correct 1 ms 2384 KB Output is correct
72 Correct 1 ms 2384 KB Output is correct
73 Correct 1 ms 2556 KB Output is correct
74 Correct 204 ms 25448 KB Output is correct
75 Correct 212 ms 23112 KB Output is correct
76 Correct 198 ms 23172 KB Output is correct
77 Correct 215 ms 23200 KB Output is correct
78 Correct 206 ms 25416 KB Output is correct
79 Correct 175 ms 25160 KB Output is correct
80 Correct 167 ms 25160 KB Output is correct
81 Correct 186 ms 23164 KB Output is correct
82 Correct 160 ms 26236 KB Output is correct
83 Correct 161 ms 26184 KB Output is correct
84 Correct 191 ms 23112 KB Output is correct
85 Correct 181 ms 25416 KB Output is correct
86 Correct 185 ms 25400 KB Output is correct
87 Correct 181 ms 23112 KB Output is correct
88 Correct 1 ms 2384 KB Output is correct
89 Correct 1 ms 2384 KB Output is correct
90 Correct 1 ms 2384 KB Output is correct
91 Correct 1 ms 2552 KB Output is correct
92 Correct 1 ms 2384 KB Output is correct
93 Correct 1 ms 2384 KB Output is correct
94 Correct 1 ms 2384 KB Output is correct
95 Correct 1 ms 2552 KB Output is correct
96 Correct 1 ms 2384 KB Output is correct
97 Correct 1 ms 2384 KB Output is correct
98 Correct 1 ms 2384 KB Output is correct
99 Correct 1 ms 2384 KB Output is correct
100 Correct 1 ms 2384 KB Output is correct
101 Correct 1 ms 2384 KB Output is correct
102 Correct 1 ms 2384 KB Output is correct
103 Correct 1 ms 2436 KB Output is correct
104 Correct 6 ms 2896 KB Output is correct
105 Correct 8 ms 2896 KB Output is correct
106 Correct 8 ms 2796 KB Output is correct
107 Correct 8 ms 2896 KB Output is correct
108 Correct 7 ms 3152 KB Output is correct
109 Correct 7 ms 2896 KB Output is correct
110 Correct 1 ms 2384 KB Output is correct
111 Correct 1 ms 2384 KB Output is correct
112 Correct 1 ms 2384 KB Output is correct
113 Correct 1 ms 2384 KB Output is correct
114 Correct 1 ms 2384 KB Output is correct
115 Correct 1 ms 2384 KB Output is correct
116 Correct 7 ms 2896 KB Output is correct
117 Correct 7 ms 2896 KB Output is correct
118 Correct 7 ms 3152 KB Output is correct
119 Correct 8 ms 2896 KB Output is correct
120 Correct 8 ms 3152 KB Output is correct
121 Correct 7 ms 3152 KB Output is correct
122 Correct 7 ms 3152 KB Output is correct
123 Correct 7 ms 2936 KB Output is correct
124 Correct 8 ms 3152 KB Output is correct
125 Correct 7 ms 3152 KB Output is correct
126 Correct 7 ms 2896 KB Output is correct
127 Correct 7 ms 2896 KB Output is correct
128 Correct 1 ms 2384 KB Output is correct
129 Correct 249 ms 27284 KB Output is correct
130 Correct 245 ms 27456 KB Output is correct
131 Correct 230 ms 23112 KB Output is correct
132 Correct 232 ms 23112 KB Output is correct
133 Correct 228 ms 23172 KB Output is correct
134 Correct 235 ms 23112 KB Output is correct
135 Correct 1 ms 2384 KB Output is correct
136 Correct 1 ms 2384 KB Output is correct
137 Correct 1 ms 2384 KB Output is correct
138 Correct 1 ms 2552 KB Output is correct
139 Correct 1 ms 2384 KB Output is correct
140 Correct 1 ms 2384 KB Output is correct
141 Correct 230 ms 23168 KB Output is correct
142 Correct 226 ms 23116 KB Output is correct
143 Correct 232 ms 23112 KB Output is correct
144 Correct 235 ms 23160 KB Output is correct
145 Correct 228 ms 23112 KB Output is correct
146 Correct 233 ms 26952 KB Output is correct
147 Correct 230 ms 23112 KB Output is correct
148 Correct 231 ms 23112 KB Output is correct
149 Correct 226 ms 27464 KB Output is correct
150 Correct 192 ms 27556 KB Output is correct
151 Correct 191 ms 23112 KB Output is correct
152 Correct 224 ms 23376 KB Output is correct
153 Correct 222 ms 23168 KB Output is correct
154 Correct 215 ms 29512 KB Output is correct
155 Correct 240 ms 29512 KB Output is correct