Submission #858142

# Submission time Handle Problem Language Result Execution time Memory
858142 2023-10-07T13:28:02 Z thangdz2k7 Fuel Station (NOI20_fuelstation) C++17
55 / 100
188 ms 23920 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];
        update(1, 1, n, x[i] + 1, -a[i]);
        if (Max[1] <= b[i]) ans = Max[1];
    }

    cout << 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 8652 KB Output is correct
5 Correct 1 ms 8536 KB Output is correct
6 Correct 1 ms 8792 KB Output is correct
7 Correct 1 ms 8536 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 8792 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 2 ms 8792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 179 ms 23920 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 8776 KB Output is correct
3 Correct 6 ms 8796 KB Output is correct
4 Correct 6 ms 8792 KB Output is correct
5 Correct 6 ms 9048 KB Output is correct
6 Correct 7 ms 8808 KB Output is correct
7 Correct 6 ms 8796 KB Output is correct
8 Correct 1 ms 8536 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
12 Correct 1 ms 8536 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 6 ms 8820 KB Output is correct
15 Correct 6 ms 8924 KB Output is correct
16 Correct 6 ms 8796 KB Output is correct
17 Correct 6 ms 8776 KB Output is correct
18 Correct 7 ms 9048 KB Output is correct
19 Correct 5 ms 8796 KB Output is correct
20 Correct 5 ms 8860 KB Output is correct
21 Correct 6 ms 8796 KB Output is correct
22 Correct 5 ms 8796 KB Output is correct
23 Correct 6 ms 8796 KB Output is correct
24 Correct 5 ms 8796 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 8776 KB Output is correct
3 Correct 6 ms 8796 KB Output is correct
4 Correct 6 ms 8792 KB Output is correct
5 Correct 6 ms 9048 KB Output is correct
6 Correct 7 ms 8808 KB Output is correct
7 Correct 6 ms 8796 KB Output is correct
8 Correct 1 ms 8536 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
12 Correct 1 ms 8536 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 6 ms 8820 KB Output is correct
15 Correct 6 ms 8924 KB Output is correct
16 Correct 6 ms 8796 KB Output is correct
17 Correct 6 ms 8776 KB Output is correct
18 Correct 7 ms 9048 KB Output is correct
19 Correct 5 ms 8796 KB Output is correct
20 Correct 5 ms 8860 KB Output is correct
21 Correct 6 ms 8796 KB Output is correct
22 Correct 5 ms 8796 KB Output is correct
23 Correct 6 ms 8796 KB Output is correct
24 Correct 5 ms 8796 KB Output is correct
25 Correct 5 ms 8796 KB Output is correct
26 Correct 1 ms 8536 KB Output is correct
27 Correct 164 ms 19780 KB Output is correct
28 Correct 188 ms 19644 KB Output is correct
29 Correct 170 ms 19320 KB Output is correct
30 Correct 166 ms 19484 KB Output is correct
31 Correct 186 ms 19884 KB Output is correct
32 Correct 173 ms 19728 KB Output is correct
33 Correct 1 ms 8540 KB Output is correct
34 Correct 1 ms 8668 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 8536 KB Output is correct
39 Correct 164 ms 20036 KB Output is correct
40 Correct 167 ms 19792 KB Output is correct
41 Correct 173 ms 20044 KB Output is correct
42 Correct 166 ms 19796 KB Output is correct
43 Correct 171 ms 19780 KB Output is correct
44 Correct 163 ms 19396 KB Output is correct
45 Correct 147 ms 19024 KB Output is correct
46 Correct 164 ms 19908 KB Output is correct
47 Correct 186 ms 21332 KB Output is correct
48 Correct 154 ms 21328 KB Output is correct
49 Correct 168 ms 19344 KB Output is correct
50 Correct 165 ms 19668 KB Output is correct
51 Correct 173 ms 19784 KB Output is correct
52 Correct 169 ms 19660 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 8652 KB Output is correct
5 Correct 1 ms 8536 KB Output is correct
6 Correct 1 ms 8792 KB Output is correct
7 Correct 1 ms 8536 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 8792 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 2 ms 8792 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 2 ms 8536 KB Output is correct
18 Correct 1 ms 8536 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 1 ms 8540 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 8540 KB Output is correct
30 Correct 1 ms 8540 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 8652 KB Output is correct
5 Correct 1 ms 8536 KB Output is correct
6 Correct 1 ms 8792 KB Output is correct
7 Correct 1 ms 8536 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 8792 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 2 ms 8792 KB Output is correct
16 Correct 1 ms 8536 KB Output is correct
17 Correct 5 ms 8776 KB Output is correct
18 Correct 6 ms 8796 KB Output is correct
19 Correct 6 ms 8792 KB Output is correct
20 Correct 6 ms 9048 KB Output is correct
21 Correct 7 ms 8808 KB Output is correct
22 Correct 6 ms 8796 KB Output is correct
23 Correct 1 ms 8536 KB Output is correct
24 Correct 2 ms 8540 KB Output is correct
25 Correct 1 ms 8540 KB Output is correct
26 Correct 2 ms 8540 KB Output is correct
27 Correct 1 ms 8536 KB Output is correct
28 Correct 2 ms 8540 KB Output is correct
29 Correct 6 ms 8820 KB Output is correct
30 Correct 6 ms 8924 KB Output is correct
31 Correct 6 ms 8796 KB Output is correct
32 Correct 6 ms 8776 KB Output is correct
33 Correct 7 ms 9048 KB Output is correct
34 Correct 5 ms 8796 KB Output is correct
35 Correct 5 ms 8860 KB Output is correct
36 Correct 6 ms 8796 KB Output is correct
37 Correct 5 ms 8796 KB Output is correct
38 Correct 6 ms 8796 KB Output is correct
39 Correct 5 ms 8796 KB Output is correct
40 Correct 5 ms 8796 KB Output is correct
41 Correct 1 ms 8540 KB Output is correct
42 Correct 6 ms 8796 KB Output is correct
43 Correct 6 ms 9052 KB Output is correct
44 Incorrect 6 ms 9064 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 8652 KB Output is correct
5 Correct 1 ms 8536 KB Output is correct
6 Correct 1 ms 8792 KB Output is correct
7 Correct 1 ms 8536 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 8792 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 2 ms 8792 KB Output is correct
16 Incorrect 179 ms 23920 KB Output isn't correct
17 Halted 0 ms 0 KB -