Submission #858146

# Submission time Handle Problem Language Result Execution time Memory
858146 2023-10-07T13:33:32 Z thangdz2k7 Fuel Station (NOI20_fuelstation) C++17
55 / 100
181 ms 15704 KB
#include <bits/stdc++.h>
#define ii pair <int, int>
#define F first
#define S second

using namespace std;

const int mod = 1e9 + 7;
const int N = 3e5 + 5;

int n, d, a[N], b[N], x[N];
int sr[N], t[N];

int Max[4 * N], lazy[4 * N];

void build(int s, int l, int r){
    if (l == r){
        Max[s] = sr[l];
        return;
    }
    int mid = l + r >> 1;
    build(2 * s, l, mid);
    build(2 * s + 1, mid + 1, r);
    Max[s] = max(Max[2 * s], Max[2 * s + 1]);
}

void update(int s, int l, int r, int u, int val){
    if (u <= l){
        lazy[s] += val;
        Max[s] += val;
        return;
    }
    int mid = l + r >> 1;
    if (mid >= u) update(2 * s, l, mid, u, val);
    update(2 * s + 1, mid + 1, r, u, val);
    Max[s] = max(Max[2 * s], Max[2 * s + 1]) + lazy[s];
}

void solve(){
    cin >> n >> d;
    for (int i = 1; i <= n; ++ i) {
        cin >> x[i] >> a[i] >> b[i];
        sr[i] = x[i];
        t[i] = i;
    }
    ++ n;
    x[n] = d;
    sr[n] = d;
    a[n] = 0;
    sort(sr + 1, sr + n + 1);
    for (int i = 1; i <= n; ++ i) x[i] = lower_bound(sr + 1, sr + n + 1, x[i]) - sr;
    sort(t + 1, t + n + 1, [&](int u, int v){
         return b[u] > b[v];
    });

    int ans = d;
    build(1, 1, n);
    for (int z = 1; z <= n; ++ z){
        //cout << Max[1] << endl;
        int i = t[z];
        if (x[i] + 1 <= n) update(1, 1, n, x[i] + 1, -a[i]);
        if (Max[1] <= b[i]) ans = Max[1];
    }

    cout << max(0, ans);
}

int main(){
    //freopen("code.inp", "r", stdin);
    //freopen("code.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    while (t --) solve();

    return 0;
}

Compilation message

FuelStation.cpp: In function 'void build(int, int, int)':
FuelStation.cpp:21:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   21 |     int mid = l + r >> 1;
      |               ~~^~~
FuelStation.cpp: In function 'void update(int, int, int, int, int)':
FuelStation.cpp:33:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   33 |     int mid = l + r >> 1;
      |               ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 176 ms 15700 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 5 ms 8540 KB Output is correct
3 Correct 6 ms 8796 KB Output is correct
4 Correct 5 ms 8668 KB Output is correct
5 Correct 5 ms 8792 KB Output is correct
6 Correct 5 ms 8540 KB Output is correct
7 Correct 5 ms 8796 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8792 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 6 ms 8792 KB Output is correct
15 Correct 6 ms 8676 KB Output is correct
16 Correct 6 ms 8804 KB Output is correct
17 Correct 6 ms 8672 KB Output is correct
18 Correct 5 ms 8664 KB Output is correct
19 Correct 5 ms 8540 KB Output is correct
20 Correct 5 ms 8796 KB Output is correct
21 Correct 7 ms 8796 KB Output is correct
22 Correct 6 ms 8536 KB Output is correct
23 Correct 5 ms 8540 KB Output is correct
24 Correct 5 ms 8540 KB Output is correct
25 Correct 5 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 5 ms 8540 KB Output is correct
3 Correct 6 ms 8796 KB Output is correct
4 Correct 5 ms 8668 KB Output is correct
5 Correct 5 ms 8792 KB Output is correct
6 Correct 5 ms 8540 KB Output is correct
7 Correct 5 ms 8796 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8792 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 6 ms 8792 KB Output is correct
15 Correct 6 ms 8676 KB Output is correct
16 Correct 6 ms 8804 KB Output is correct
17 Correct 6 ms 8672 KB Output is correct
18 Correct 5 ms 8664 KB Output is correct
19 Correct 5 ms 8540 KB Output is correct
20 Correct 5 ms 8796 KB Output is correct
21 Correct 7 ms 8796 KB Output is correct
22 Correct 6 ms 8536 KB Output is correct
23 Correct 5 ms 8540 KB Output is correct
24 Correct 5 ms 8540 KB Output is correct
25 Correct 5 ms 8796 KB Output is correct
26 Correct 1 ms 8536 KB Output is correct
27 Correct 168 ms 15696 KB Output is correct
28 Correct 180 ms 15600 KB Output is correct
29 Correct 168 ms 15700 KB Output is correct
30 Correct 165 ms 15704 KB Output is correct
31 Correct 176 ms 15700 KB Output is correct
32 Correct 181 ms 15696 KB Output is correct
33 Correct 1 ms 8540 KB Output is correct
34 Correct 1 ms 8540 KB Output is correct
35 Correct 1 ms 8540 KB Output is correct
36 Correct 1 ms 8540 KB Output is correct
37 Correct 1 ms 8540 KB Output is correct
38 Correct 1 ms 8540 KB Output is correct
39 Correct 168 ms 15696 KB Output is correct
40 Correct 171 ms 15508 KB Output is correct
41 Correct 167 ms 15700 KB Output is correct
42 Correct 164 ms 15504 KB Output is correct
43 Correct 172 ms 15696 KB Output is correct
44 Correct 160 ms 15700 KB Output is correct
45 Correct 149 ms 15604 KB Output is correct
46 Correct 165 ms 15512 KB Output is correct
47 Correct 173 ms 15512 KB Output is correct
48 Correct 150 ms 15576 KB Output is correct
49 Correct 159 ms 15696 KB Output is correct
50 Correct 161 ms 15680 KB Output is correct
51 Correct 174 ms 15468 KB Output is correct
52 Correct 158 ms 15696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8660 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 1 ms 8792 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8540 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 1 ms 8540 KB Output is correct
25 Correct 1 ms 8540 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 1 ms 8540 KB Output is correct
29 Correct 1 ms 8696 KB Output is correct
30 Correct 1 ms 8536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8660 KB Output is correct
16 Correct 1 ms 8536 KB Output is correct
17 Correct 5 ms 8540 KB Output is correct
18 Correct 6 ms 8796 KB Output is correct
19 Correct 5 ms 8668 KB Output is correct
20 Correct 5 ms 8792 KB Output is correct
21 Correct 5 ms 8540 KB Output is correct
22 Correct 5 ms 8796 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 1 ms 8540 KB Output is correct
25 Correct 1 ms 8792 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 1 ms 8540 KB Output is correct
29 Correct 6 ms 8792 KB Output is correct
30 Correct 6 ms 8676 KB Output is correct
31 Correct 6 ms 8804 KB Output is correct
32 Correct 6 ms 8672 KB Output is correct
33 Correct 5 ms 8664 KB Output is correct
34 Correct 5 ms 8540 KB Output is correct
35 Correct 5 ms 8796 KB Output is correct
36 Correct 7 ms 8796 KB Output is correct
37 Correct 6 ms 8536 KB Output is correct
38 Correct 5 ms 8540 KB Output is correct
39 Correct 5 ms 8540 KB Output is correct
40 Correct 5 ms 8796 KB Output is correct
41 Correct 1 ms 8540 KB Output is correct
42 Correct 5 ms 8540 KB Output is correct
43 Correct 6 ms 8796 KB Output is correct
44 Incorrect 6 ms 8796 KB Output isn't correct
45 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8660 KB Output is correct
16 Incorrect 176 ms 15700 KB Output isn't correct
17 Halted 0 ms 0 KB -