Submission #1106024

# Submission time Handle Problem Language Result Execution time Memory
1106024 2024-10-29T01:37:06 Z ShadowShark Fuel Station (NOI20_fuelstation) C++17
100 / 100
369 ms 42028 KB
#include <bits/stdc++.h>
using namespace std;

const int maxN = 3e5 + 5;
int n, D;
int x[maxN], a[maxN], b[maxN];
pair<int, int> des[maxN];
vector<int> val, place;

struct node {
    long long val, lazy;
} st[4 * maxN];

void down(int id) {
    long long t = st[id].lazy;

    st[2 * id].val += t;
    st[2 * id + 1].val += t;

    st[2 * id].lazy += t;
    st[2 * id + 1].lazy += t;

    st[id].lazy = 0;
}

void build(int id, int l, int r) {
    if (l == r) {
        st[id].val = place[l - 1];
        return ;
    }

    int mid = (l + r) >> 1;

    build(2 * id, l, mid);
    build(2 * id + 1, mid + 1, r);

    st[id].val = max(st[2 * id].val, st[2 * id + 1].val);
}

void update(int id, int l, int r, int u, int v, int val) {
    if (v < l || r < u) return ;

    if (u <= l && r <= v) {
        st[id].lazy += val;
        st[id].val += val;
        return ;
    }

    int mid = (l + r) >> 1;
    down(id);

    update(2 * id, l, mid, u, v, val);
    update(2 * id + 1, mid + 1, r, u, v, val);

    st[id].val = max(st[2 * id].val, st[2 * id + 1].val);
}

long long get(int id, int l, int r, int pos) {
    if (l == r) return st[id].val;

    int mid = (l + r) >> 1;
    down(id);

    if (pos <= mid) return get(2 * id, l, mid, pos);
    return get(2 * id + 1, mid + 1, r, pos);
}

vector<pair<int, int>> query;
long long find_ans(int res) {
    long long mn = 1e18, sum = res;
    for (int i = 1; i <= n; i++)
        if (res <= b[i]) query.push_back({x[i], a[i]});
    sort(query.begin(), query.end());
    int pre = 0;
    for (auto it: query) {
        sum = sum - (it.first - pre);
        mn = min(mn, sum);
        sum = sum + it.second;
        pre = it.first;
    }
    return res - mn;
}

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

    cin >> n >> D;

    for (int i = 1; i <= n; i++)
        cin >> x[i] >> a[i] >> b[i];
    n++;
    x[n] = D; a[n] = 0; b[n] = D;

    for (int i = 1; i <= n; i++) {
        des[i] = {b[i], i};
        place.push_back(x[i]);
        val.push_back(b[i]);
    }

    sort(des + 1, des + n + 1);

    sort(val.begin(), val.end());
    val.erase(unique(val.begin(), val.end()), val.end());
    sort(place.begin(), place.end());
    place.erase(unique(place.begin(), place.end()), place.end());

    int m = place.size();
    build(1, 1, m);

    for (int i = 1; i <= n; i++) {
        int pos = lower_bound(place.begin(), place.end(), x[i]) - place.begin() + 1;
        update(1, 1, m, pos + 1, m, -a[i]);
    }

    if (st[1].val <= val[0]) {
        cout << find_ans(val[0]);
        return 0;
    }

    int id = 1;
    for (int i = 1; i < val.size(); i++) {
        int v = val[i - 1];
        while (des[id].first == v) {
            int i = des[id].second;
            int pos = lower_bound(place.begin(), place.end(), x[i]) - place.begin() + 1;
            update(1, 1, m, pos + 1, m, a[i]);
            id++;
        }
        if (st[1].val <= val[i]) {
            cout << find_ans(val[i]);
            return 0;
        }
    }

    return 0;
}

Compilation message

FuelStation.cpp: In function 'int main()':
FuelStation.cpp:121:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  121 |     for (int i = 1; i < val.size(); i++) {
      |                     ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 1 ms 4572 KB Output is correct
13 Correct 2 ms 4432 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 1 ms 4604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 194 ms 27436 KB Output is correct
2 Correct 195 ms 27440 KB Output is correct
3 Correct 215 ms 27180 KB Output is correct
4 Correct 174 ms 25128 KB Output is correct
5 Correct 184 ms 25856 KB Output is correct
6 Correct 204 ms 26668 KB Output is correct
7 Correct 217 ms 26840 KB Output is correct
8 Correct 179 ms 25004 KB Output is correct
9 Correct 221 ms 27948 KB Output is correct
10 Correct 178 ms 24620 KB Output is correct
11 Correct 214 ms 26664 KB Output is correct
12 Correct 162 ms 25132 KB Output is correct
13 Correct 220 ms 26664 KB Output is correct
14 Correct 198 ms 27328 KB Output is correct
15 Correct 159 ms 25132 KB Output is correct
16 Correct 191 ms 27948 KB Output is correct
17 Correct 164 ms 25896 KB Output is correct
18 Correct 200 ms 27436 KB Output is correct
19 Correct 158 ms 25132 KB Output is correct
20 Correct 214 ms 27124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 8 ms 5200 KB Output is correct
3 Correct 8 ms 7248 KB Output is correct
4 Correct 7 ms 7248 KB Output is correct
5 Correct 8 ms 7248 KB Output is correct
6 Correct 7 ms 7052 KB Output is correct
7 Correct 8 ms 7248 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 ms 4552 KB Output is correct
12 Correct 1 ms 4600 KB Output is correct
13 Correct 1 ms 4432 KB Output is correct
14 Correct 7 ms 4888 KB Output is correct
15 Correct 8 ms 4956 KB Output is correct
16 Correct 8 ms 4944 KB Output is correct
17 Correct 8 ms 7140 KB Output is correct
18 Correct 9 ms 6992 KB Output is correct
19 Correct 6 ms 4944 KB Output is correct
20 Correct 7 ms 4944 KB Output is correct
21 Correct 6 ms 4944 KB Output is correct
22 Correct 6 ms 4944 KB Output is correct
23 Correct 6 ms 4944 KB Output is correct
24 Correct 6 ms 4996 KB Output is correct
25 Correct 6 ms 4944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 8 ms 5200 KB Output is correct
3 Correct 8 ms 7248 KB Output is correct
4 Correct 7 ms 7248 KB Output is correct
5 Correct 8 ms 7248 KB Output is correct
6 Correct 7 ms 7052 KB Output is correct
7 Correct 8 ms 7248 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 ms 4552 KB Output is correct
12 Correct 1 ms 4600 KB Output is correct
13 Correct 1 ms 4432 KB Output is correct
14 Correct 7 ms 4888 KB Output is correct
15 Correct 8 ms 4956 KB Output is correct
16 Correct 8 ms 4944 KB Output is correct
17 Correct 8 ms 7140 KB Output is correct
18 Correct 9 ms 6992 KB Output is correct
19 Correct 6 ms 4944 KB Output is correct
20 Correct 7 ms 4944 KB Output is correct
21 Correct 6 ms 4944 KB Output is correct
22 Correct 6 ms 4944 KB Output is correct
23 Correct 6 ms 4944 KB Output is correct
24 Correct 6 ms 4996 KB Output is correct
25 Correct 6 ms 4944 KB Output is correct
26 Correct 1 ms 4432 KB Output is correct
27 Correct 162 ms 20940 KB Output is correct
28 Correct 201 ms 23128 KB Output is correct
29 Correct 190 ms 22736 KB Output is correct
30 Correct 191 ms 22824 KB Output is correct
31 Correct 195 ms 23352 KB Output is correct
32 Correct 201 ms 23080 KB Output is correct
33 Correct 1 ms 4432 KB Output is correct
34 Correct 1 ms 4600 KB Output is correct
35 Correct 1 ms 4432 KB Output is correct
36 Correct 1 ms 4432 KB Output is correct
37 Correct 1 ms 4432 KB Output is correct
38 Correct 1 ms 4432 KB Output is correct
39 Correct 189 ms 16072 KB Output is correct
40 Correct 197 ms 16032 KB Output is correct
41 Correct 198 ms 16052 KB Output is correct
42 Correct 184 ms 15960 KB Output is correct
43 Correct 228 ms 17252 KB Output is correct
44 Correct 197 ms 18344 KB Output is correct
45 Correct 213 ms 16300 KB Output is correct
46 Correct 165 ms 21036 KB Output is correct
47 Correct 160 ms 22500 KB Output is correct
48 Correct 163 ms 22572 KB Output is correct
49 Correct 184 ms 20524 KB Output is correct
50 Correct 165 ms 20780 KB Output is correct
51 Correct 182 ms 20780 KB Output is correct
52 Correct 165 ms 20512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 1 ms 4572 KB Output is correct
13 Correct 2 ms 4432 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 1 ms 4604 KB Output is correct
16 Correct 2 ms 4432 KB Output is correct
17 Correct 1 ms 4432 KB Output is correct
18 Correct 1 ms 4432 KB Output is correct
19 Correct 1 ms 4432 KB Output is correct
20 Correct 1 ms 4432 KB Output is correct
21 Correct 1 ms 4560 KB Output is correct
22 Correct 1 ms 4432 KB Output is correct
23 Correct 1 ms 4432 KB Output is correct
24 Correct 1 ms 4432 KB Output is correct
25 Correct 1 ms 4572 KB Output is correct
26 Correct 1 ms 4432 KB Output is correct
27 Correct 1 ms 4432 KB Output is correct
28 Correct 1 ms 4432 KB Output is correct
29 Correct 1 ms 4568 KB Output is correct
30 Correct 1 ms 4432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 1 ms 4572 KB Output is correct
13 Correct 2 ms 4432 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 1 ms 4604 KB Output is correct
16 Correct 1 ms 4432 KB Output is correct
17 Correct 8 ms 5200 KB Output is correct
18 Correct 8 ms 7248 KB Output is correct
19 Correct 7 ms 7248 KB Output is correct
20 Correct 8 ms 7248 KB Output is correct
21 Correct 7 ms 7052 KB Output is correct
22 Correct 8 ms 7248 KB Output is correct
23 Correct 1 ms 4432 KB Output is correct
24 Correct 1 ms 4432 KB Output is correct
25 Correct 1 ms 4432 KB Output is correct
26 Correct 1 ms 4552 KB Output is correct
27 Correct 1 ms 4600 KB Output is correct
28 Correct 1 ms 4432 KB Output is correct
29 Correct 7 ms 4888 KB Output is correct
30 Correct 8 ms 4956 KB Output is correct
31 Correct 8 ms 4944 KB Output is correct
32 Correct 8 ms 7140 KB Output is correct
33 Correct 9 ms 6992 KB Output is correct
34 Correct 6 ms 4944 KB Output is correct
35 Correct 7 ms 4944 KB Output is correct
36 Correct 6 ms 4944 KB Output is correct
37 Correct 6 ms 4944 KB Output is correct
38 Correct 6 ms 4944 KB Output is correct
39 Correct 6 ms 4996 KB Output is correct
40 Correct 6 ms 4944 KB Output is correct
41 Correct 1 ms 4432 KB Output is correct
42 Correct 7 ms 4944 KB Output is correct
43 Correct 8 ms 7268 KB Output is correct
44 Correct 8 ms 7248 KB Output is correct
45 Correct 8 ms 7248 KB Output is correct
46 Correct 8 ms 7248 KB Output is correct
47 Correct 9 ms 7248 KB Output is correct
48 Correct 1 ms 4432 KB Output is correct
49 Correct 1 ms 4432 KB Output is correct
50 Correct 1 ms 4432 KB Output is correct
51 Correct 1 ms 4432 KB Output is correct
52 Correct 1 ms 4432 KB Output is correct
53 Correct 1 ms 4432 KB Output is correct
54 Correct 10 ms 7312 KB Output is correct
55 Correct 9 ms 7248 KB Output is correct
56 Correct 10 ms 7248 KB Output is correct
57 Correct 15 ms 7248 KB Output is correct
58 Correct 10 ms 7248 KB Output is correct
59 Correct 7 ms 4944 KB Output is correct
60 Correct 7 ms 5100 KB Output is correct
61 Correct 8 ms 5328 KB Output is correct
62 Correct 7 ms 5208 KB Output is correct
63 Correct 7 ms 4944 KB Output is correct
64 Correct 8 ms 5200 KB Output is correct
65 Correct 10 ms 5200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 1 ms 4572 KB Output is correct
13 Correct 2 ms 4432 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 1 ms 4604 KB Output is correct
16 Correct 194 ms 27436 KB Output is correct
17 Correct 195 ms 27440 KB Output is correct
18 Correct 215 ms 27180 KB Output is correct
19 Correct 174 ms 25128 KB Output is correct
20 Correct 184 ms 25856 KB Output is correct
21 Correct 204 ms 26668 KB Output is correct
22 Correct 217 ms 26840 KB Output is correct
23 Correct 179 ms 25004 KB Output is correct
24 Correct 221 ms 27948 KB Output is correct
25 Correct 178 ms 24620 KB Output is correct
26 Correct 214 ms 26664 KB Output is correct
27 Correct 162 ms 25132 KB Output is correct
28 Correct 220 ms 26664 KB Output is correct
29 Correct 198 ms 27328 KB Output is correct
30 Correct 159 ms 25132 KB Output is correct
31 Correct 191 ms 27948 KB Output is correct
32 Correct 164 ms 25896 KB Output is correct
33 Correct 200 ms 27436 KB Output is correct
34 Correct 158 ms 25132 KB Output is correct
35 Correct 214 ms 27124 KB Output is correct
36 Correct 1 ms 4432 KB Output is correct
37 Correct 8 ms 5200 KB Output is correct
38 Correct 8 ms 7248 KB Output is correct
39 Correct 7 ms 7248 KB Output is correct
40 Correct 8 ms 7248 KB Output is correct
41 Correct 7 ms 7052 KB Output is correct
42 Correct 8 ms 7248 KB Output is correct
43 Correct 1 ms 4432 KB Output is correct
44 Correct 1 ms 4432 KB Output is correct
45 Correct 1 ms 4432 KB Output is correct
46 Correct 1 ms 4552 KB Output is correct
47 Correct 1 ms 4600 KB Output is correct
48 Correct 1 ms 4432 KB Output is correct
49 Correct 7 ms 4888 KB Output is correct
50 Correct 8 ms 4956 KB Output is correct
51 Correct 8 ms 4944 KB Output is correct
52 Correct 8 ms 7140 KB Output is correct
53 Correct 9 ms 6992 KB Output is correct
54 Correct 6 ms 4944 KB Output is correct
55 Correct 7 ms 4944 KB Output is correct
56 Correct 6 ms 4944 KB Output is correct
57 Correct 6 ms 4944 KB Output is correct
58 Correct 6 ms 4944 KB Output is correct
59 Correct 6 ms 4996 KB Output is correct
60 Correct 6 ms 4944 KB Output is correct
61 Correct 1 ms 4432 KB Output is correct
62 Correct 162 ms 20940 KB Output is correct
63 Correct 201 ms 23128 KB Output is correct
64 Correct 190 ms 22736 KB Output is correct
65 Correct 191 ms 22824 KB Output is correct
66 Correct 195 ms 23352 KB Output is correct
67 Correct 201 ms 23080 KB Output is correct
68 Correct 1 ms 4432 KB Output is correct
69 Correct 1 ms 4600 KB Output is correct
70 Correct 1 ms 4432 KB Output is correct
71 Correct 1 ms 4432 KB Output is correct
72 Correct 1 ms 4432 KB Output is correct
73 Correct 1 ms 4432 KB Output is correct
74 Correct 189 ms 16072 KB Output is correct
75 Correct 197 ms 16032 KB Output is correct
76 Correct 198 ms 16052 KB Output is correct
77 Correct 184 ms 15960 KB Output is correct
78 Correct 228 ms 17252 KB Output is correct
79 Correct 197 ms 18344 KB Output is correct
80 Correct 213 ms 16300 KB Output is correct
81 Correct 165 ms 21036 KB Output is correct
82 Correct 160 ms 22500 KB Output is correct
83 Correct 163 ms 22572 KB Output is correct
84 Correct 184 ms 20524 KB Output is correct
85 Correct 165 ms 20780 KB Output is correct
86 Correct 182 ms 20780 KB Output is correct
87 Correct 165 ms 20512 KB Output is correct
88 Correct 2 ms 4432 KB Output is correct
89 Correct 1 ms 4432 KB Output is correct
90 Correct 1 ms 4432 KB Output is correct
91 Correct 1 ms 4432 KB Output is correct
92 Correct 1 ms 4432 KB Output is correct
93 Correct 1 ms 4560 KB Output is correct
94 Correct 1 ms 4432 KB Output is correct
95 Correct 1 ms 4432 KB Output is correct
96 Correct 1 ms 4432 KB Output is correct
97 Correct 1 ms 4572 KB Output is correct
98 Correct 1 ms 4432 KB Output is correct
99 Correct 1 ms 4432 KB Output is correct
100 Correct 1 ms 4432 KB Output is correct
101 Correct 1 ms 4568 KB Output is correct
102 Correct 1 ms 4432 KB Output is correct
103 Correct 1 ms 4432 KB Output is correct
104 Correct 7 ms 4944 KB Output is correct
105 Correct 8 ms 7268 KB Output is correct
106 Correct 8 ms 7248 KB Output is correct
107 Correct 8 ms 7248 KB Output is correct
108 Correct 8 ms 7248 KB Output is correct
109 Correct 9 ms 7248 KB Output is correct
110 Correct 1 ms 4432 KB Output is correct
111 Correct 1 ms 4432 KB Output is correct
112 Correct 1 ms 4432 KB Output is correct
113 Correct 1 ms 4432 KB Output is correct
114 Correct 1 ms 4432 KB Output is correct
115 Correct 1 ms 4432 KB Output is correct
116 Correct 10 ms 7312 KB Output is correct
117 Correct 9 ms 7248 KB Output is correct
118 Correct 10 ms 7248 KB Output is correct
119 Correct 15 ms 7248 KB Output is correct
120 Correct 10 ms 7248 KB Output is correct
121 Correct 7 ms 4944 KB Output is correct
122 Correct 7 ms 5100 KB Output is correct
123 Correct 8 ms 5328 KB Output is correct
124 Correct 7 ms 5208 KB Output is correct
125 Correct 7 ms 4944 KB Output is correct
126 Correct 8 ms 5200 KB Output is correct
127 Correct 10 ms 5200 KB Output is correct
128 Correct 1 ms 4432 KB Output is correct
129 Correct 227 ms 26416 KB Output is correct
130 Correct 257 ms 41504 KB Output is correct
131 Correct 260 ms 42028 KB Output is correct
132 Correct 255 ms 41528 KB Output is correct
133 Correct 255 ms 41472 KB Output is correct
134 Correct 255 ms 42028 KB Output is correct
135 Correct 1 ms 4432 KB Output is correct
136 Correct 1 ms 4432 KB Output is correct
137 Correct 1 ms 4432 KB Output is correct
138 Correct 1 ms 4600 KB Output is correct
139 Correct 1 ms 4432 KB Output is correct
140 Correct 1 ms 4432 KB Output is correct
141 Correct 369 ms 36040 KB Output is correct
142 Correct 351 ms 35752 KB Output is correct
143 Correct 328 ms 36784 KB Output is correct
144 Correct 345 ms 36060 KB Output is correct
145 Correct 340 ms 36012 KB Output is correct
146 Correct 295 ms 35900 KB Output is correct
147 Correct 268 ms 38864 KB Output is correct
148 Correct 300 ms 38316 KB Output is correct
149 Correct 225 ms 27084 KB Output is correct
150 Correct 176 ms 25168 KB Output is correct
151 Correct 174 ms 25132 KB Output is correct
152 Correct 225 ms 26940 KB Output is correct
153 Correct 192 ms 24884 KB Output is correct
154 Correct 186 ms 24880 KB Output is correct
155 Correct 224 ms 27184 KB Output is correct