Submission #330814

# Submission time Handle Problem Language Result Execution time Memory
330814 2020-11-26T16:17:41 Z jungsnow Fuel Station (NOI20_fuelstation) C++14
100 / 100
1118 ms 70684 KB
#include<bits/stdc++.h>
#define int long long

using namespace std;
using ll = long long;

const int maxn = 300100;
const ll inf = 1e18;

struct sta {
    int A, B, X;
    sta() {}
    sta(int A, int B, int X) : A(A), B(B), X(X) {}
    bool operator < (const sta &other) const {
        return B > other.B;
    }
};

struct ST {
    int N;
    vector<ll> lazy;
    vector<ll> st;
    ST(int N = 0) : N(N), lazy(N << 2), st(N << 2) {}
    void pop(int v) {
        st[v] = max(st[v << 1], st[v << 1 | 1]);
    }
    void apply(int v, int lz) {
        lazy[v] += lz;
        st[v] += lz;
    }
    void push(int v) {
        if (lazy[v]) {
            apply(v << 1, lazy[v]);
            apply(v << 1 | 1, lazy[v]);
        }
        lazy[v] = 0;
    }
    void upd(int v, int l, int r, int x, int y, int val) {
        if (l > r || l > y || r < x) return;
        if (x <= l && r <= y) {
            apply(v, val);
            return;
        }
        int md = (l + r) >> 1;
        push(v);
        upd(v << 1, l, md, x, y, val);
        upd(v << 1 | 1, md + 1, r, x, y, val);
        pop(v);
    }
};

int N, M, D, id[maxn];
bool on[maxn];
ll Ans;
sta V[maxn];

signed main() {
//    freopen("cc.inp", "r", stdin);
//    freopen("cc.out", "w", stdout);
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> N >> D;
    set<int> S;
    for (int i = 1; i <= N; ++i) {
        cin >> V[i].X >> V[i].A >> V[i].B;
        S.insert(V[i].X);
    }
    S.insert(D);
    map<int, int> mp;
    for (auto it = S.begin(); it != S.end(); ++it) {
        mp[*it] = ++M;
        id[M] = *it;
    }
    for (int i = 1; i <= N; ++i) {
        V[i].X = mp[V[i].X];
    }
    sort(V + 1, V + 1 + N);
    ST T(M);
    T.upd(1, 1, M, mp[D], mp[D], D);
    Ans = D;
    for (int i = 1; i <= N; ++i) {
        if (!on[V[i].X]) {
            T.upd(1, 1, M, V[i].X, V[i].X, id[V[i].X]);
            on[V[i].X] = 1;
        }
        T.upd(1, 1, M, V[i].X + 1, M, -V[i].A);
        ll Tm = T.st[1];
        if (Tm > V[i].B) continue;
        Ans = min(Ans, Tm);
    }
    cout << Ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 323 ms 9708 KB Output is correct
2 Correct 288 ms 9708 KB Output is correct
3 Correct 287 ms 9708 KB Output is correct
4 Correct 201 ms 7660 KB Output is correct
5 Correct 211 ms 7652 KB Output is correct
6 Correct 290 ms 9760 KB Output is correct
7 Correct 320 ms 9708 KB Output is correct
8 Correct 200 ms 7556 KB Output is correct
9 Correct 291 ms 9756 KB Output is correct
10 Correct 195 ms 7556 KB Output is correct
11 Correct 287 ms 9708 KB Output is correct
12 Correct 203 ms 7524 KB Output is correct
13 Correct 286 ms 9836 KB Output is correct
14 Correct 293 ms 9708 KB Output is correct
15 Correct 200 ms 7532 KB Output is correct
16 Correct 299 ms 9992 KB Output is correct
17 Correct 201 ms 7532 KB Output is correct
18 Correct 292 ms 9836 KB Output is correct
19 Correct 199 ms 7532 KB Output is correct
20 Correct 292 ms 9708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 6 ms 748 KB Output is correct
3 Correct 15 ms 2540 KB Output is correct
4 Correct 15 ms 2540 KB Output is correct
5 Correct 15 ms 2540 KB Output is correct
6 Correct 16 ms 2540 KB Output is correct
7 Correct 15 ms 2540 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 8 ms 876 KB Output is correct
15 Correct 8 ms 1004 KB Output is correct
16 Correct 9 ms 1132 KB Output is correct
17 Correct 11 ms 1516 KB Output is correct
18 Correct 12 ms 1644 KB Output is correct
19 Correct 7 ms 748 KB Output is correct
20 Correct 8 ms 1004 KB Output is correct
21 Correct 8 ms 1004 KB Output is correct
22 Correct 6 ms 748 KB Output is correct
23 Correct 5 ms 768 KB Output is correct
24 Correct 6 ms 748 KB Output is correct
25 Correct 7 ms 1004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 6 ms 748 KB Output is correct
3 Correct 15 ms 2540 KB Output is correct
4 Correct 15 ms 2540 KB Output is correct
5 Correct 15 ms 2540 KB Output is correct
6 Correct 16 ms 2540 KB Output is correct
7 Correct 15 ms 2540 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 8 ms 876 KB Output is correct
15 Correct 8 ms 1004 KB Output is correct
16 Correct 9 ms 1132 KB Output is correct
17 Correct 11 ms 1516 KB Output is correct
18 Correct 12 ms 1644 KB Output is correct
19 Correct 7 ms 748 KB Output is correct
20 Correct 8 ms 1004 KB Output is correct
21 Correct 8 ms 1004 KB Output is correct
22 Correct 6 ms 748 KB Output is correct
23 Correct 5 ms 768 KB Output is correct
24 Correct 6 ms 748 KB Output is correct
25 Correct 7 ms 1004 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 179 ms 11780 KB Output is correct
28 Correct 266 ms 13548 KB Output is correct
29 Correct 254 ms 13036 KB Output is correct
30 Correct 258 ms 13036 KB Output is correct
31 Correct 266 ms 13648 KB Output is correct
32 Correct 260 ms 13420 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 186 ms 11884 KB Output is correct
40 Correct 199 ms 11884 KB Output is correct
41 Correct 194 ms 11884 KB Output is correct
42 Correct 183 ms 11884 KB Output is correct
43 Correct 232 ms 12652 KB Output is correct
44 Correct 233 ms 12268 KB Output is correct
45 Correct 239 ms 12524 KB Output is correct
46 Correct 184 ms 12044 KB Output is correct
47 Correct 188 ms 13292 KB Output is correct
48 Correct 187 ms 13292 KB Output is correct
49 Correct 201 ms 11372 KB Output is correct
50 Correct 175 ms 11500 KB Output is correct
51 Correct 186 ms 11628 KB Output is correct
52 Correct 174 ms 11244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 6 ms 748 KB Output is correct
18 Correct 15 ms 2540 KB Output is correct
19 Correct 15 ms 2540 KB Output is correct
20 Correct 15 ms 2540 KB Output is correct
21 Correct 16 ms 2540 KB Output is correct
22 Correct 15 ms 2540 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 8 ms 876 KB Output is correct
30 Correct 8 ms 1004 KB Output is correct
31 Correct 9 ms 1132 KB Output is correct
32 Correct 11 ms 1516 KB Output is correct
33 Correct 12 ms 1644 KB Output is correct
34 Correct 7 ms 748 KB Output is correct
35 Correct 8 ms 1004 KB Output is correct
36 Correct 8 ms 1004 KB Output is correct
37 Correct 6 ms 748 KB Output is correct
38 Correct 5 ms 768 KB Output is correct
39 Correct 6 ms 748 KB Output is correct
40 Correct 7 ms 1004 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 6 ms 896 KB Output is correct
43 Correct 16 ms 2808 KB Output is correct
44 Correct 16 ms 2668 KB Output is correct
45 Correct 16 ms 2668 KB Output is correct
46 Correct 20 ms 2668 KB Output is correct
47 Correct 17 ms 2668 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 1 ms 364 KB Output is correct
50 Correct 1 ms 364 KB Output is correct
51 Correct 1 ms 364 KB Output is correct
52 Correct 1 ms 364 KB Output is correct
53 Correct 1 ms 364 KB Output is correct
54 Correct 18 ms 2668 KB Output is correct
55 Correct 16 ms 2668 KB Output is correct
56 Correct 16 ms 2772 KB Output is correct
57 Correct 16 ms 2668 KB Output is correct
58 Correct 16 ms 2668 KB Output is correct
59 Correct 6 ms 876 KB Output is correct
60 Correct 9 ms 1132 KB Output is correct
61 Correct 8 ms 1132 KB Output is correct
62 Correct 7 ms 948 KB Output is correct
63 Correct 8 ms 1004 KB Output is correct
64 Correct 9 ms 1004 KB Output is correct
65 Correct 8 ms 1004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 323 ms 9708 KB Output is correct
17 Correct 288 ms 9708 KB Output is correct
18 Correct 287 ms 9708 KB Output is correct
19 Correct 201 ms 7660 KB Output is correct
20 Correct 211 ms 7652 KB Output is correct
21 Correct 290 ms 9760 KB Output is correct
22 Correct 320 ms 9708 KB Output is correct
23 Correct 200 ms 7556 KB Output is correct
24 Correct 291 ms 9756 KB Output is correct
25 Correct 195 ms 7556 KB Output is correct
26 Correct 287 ms 9708 KB Output is correct
27 Correct 203 ms 7524 KB Output is correct
28 Correct 286 ms 9836 KB Output is correct
29 Correct 293 ms 9708 KB Output is correct
30 Correct 200 ms 7532 KB Output is correct
31 Correct 299 ms 9992 KB Output is correct
32 Correct 201 ms 7532 KB Output is correct
33 Correct 292 ms 9836 KB Output is correct
34 Correct 199 ms 7532 KB Output is correct
35 Correct 292 ms 9708 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 6 ms 748 KB Output is correct
38 Correct 15 ms 2540 KB Output is correct
39 Correct 15 ms 2540 KB Output is correct
40 Correct 15 ms 2540 KB Output is correct
41 Correct 16 ms 2540 KB Output is correct
42 Correct 15 ms 2540 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 8 ms 876 KB Output is correct
50 Correct 8 ms 1004 KB Output is correct
51 Correct 9 ms 1132 KB Output is correct
52 Correct 11 ms 1516 KB Output is correct
53 Correct 12 ms 1644 KB Output is correct
54 Correct 7 ms 748 KB Output is correct
55 Correct 8 ms 1004 KB Output is correct
56 Correct 8 ms 1004 KB Output is correct
57 Correct 6 ms 748 KB Output is correct
58 Correct 5 ms 768 KB Output is correct
59 Correct 6 ms 748 KB Output is correct
60 Correct 7 ms 1004 KB Output is correct
61 Correct 1 ms 364 KB Output is correct
62 Correct 179 ms 11780 KB Output is correct
63 Correct 266 ms 13548 KB Output is correct
64 Correct 254 ms 13036 KB Output is correct
65 Correct 258 ms 13036 KB Output is correct
66 Correct 266 ms 13648 KB Output is correct
67 Correct 260 ms 13420 KB Output is correct
68 Correct 1 ms 364 KB Output is correct
69 Correct 1 ms 364 KB Output is correct
70 Correct 1 ms 364 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 1 ms 364 KB Output is correct
73 Correct 1 ms 364 KB Output is correct
74 Correct 186 ms 11884 KB Output is correct
75 Correct 199 ms 11884 KB Output is correct
76 Correct 194 ms 11884 KB Output is correct
77 Correct 183 ms 11884 KB Output is correct
78 Correct 232 ms 12652 KB Output is correct
79 Correct 233 ms 12268 KB Output is correct
80 Correct 239 ms 12524 KB Output is correct
81 Correct 184 ms 12044 KB Output is correct
82 Correct 188 ms 13292 KB Output is correct
83 Correct 187 ms 13292 KB Output is correct
84 Correct 201 ms 11372 KB Output is correct
85 Correct 175 ms 11500 KB Output is correct
86 Correct 186 ms 11628 KB Output is correct
87 Correct 174 ms 11244 KB Output is correct
88 Correct 1 ms 364 KB Output is correct
89 Correct 1 ms 364 KB Output is correct
90 Correct 1 ms 364 KB Output is correct
91 Correct 1 ms 364 KB Output is correct
92 Correct 1 ms 364 KB Output is correct
93 Correct 1 ms 364 KB Output is correct
94 Correct 1 ms 364 KB Output is correct
95 Correct 1 ms 364 KB Output is correct
96 Correct 1 ms 364 KB Output is correct
97 Correct 1 ms 364 KB Output is correct
98 Correct 1 ms 364 KB Output is correct
99 Correct 1 ms 364 KB Output is correct
100 Correct 1 ms 364 KB Output is correct
101 Correct 1 ms 364 KB Output is correct
102 Correct 1 ms 364 KB Output is correct
103 Correct 1 ms 364 KB Output is correct
104 Correct 6 ms 896 KB Output is correct
105 Correct 16 ms 2808 KB Output is correct
106 Correct 16 ms 2668 KB Output is correct
107 Correct 16 ms 2668 KB Output is correct
108 Correct 20 ms 2668 KB Output is correct
109 Correct 17 ms 2668 KB Output is correct
110 Correct 1 ms 364 KB Output is correct
111 Correct 1 ms 364 KB Output is correct
112 Correct 1 ms 364 KB Output is correct
113 Correct 1 ms 364 KB Output is correct
114 Correct 1 ms 364 KB Output is correct
115 Correct 1 ms 364 KB Output is correct
116 Correct 18 ms 2668 KB Output is correct
117 Correct 16 ms 2668 KB Output is correct
118 Correct 16 ms 2772 KB Output is correct
119 Correct 16 ms 2668 KB Output is correct
120 Correct 16 ms 2668 KB Output is correct
121 Correct 6 ms 876 KB Output is correct
122 Correct 9 ms 1132 KB Output is correct
123 Correct 8 ms 1132 KB Output is correct
124 Correct 7 ms 948 KB Output is correct
125 Correct 8 ms 1004 KB Output is correct
126 Correct 9 ms 1004 KB Output is correct
127 Correct 8 ms 1004 KB Output is correct
128 Correct 1 ms 364 KB Output is correct
129 Correct 308 ms 17260 KB Output is correct
130 Correct 1079 ms 69892 KB Output is correct
131 Correct 1075 ms 70636 KB Output is correct
132 Correct 1090 ms 69972 KB Output is correct
133 Correct 1081 ms 69868 KB Output is correct
134 Correct 1105 ms 70508 KB Output is correct
135 Correct 1 ms 364 KB Output is correct
136 Correct 1 ms 364 KB Output is correct
137 Correct 1 ms 364 KB Output is correct
138 Correct 1 ms 364 KB Output is correct
139 Correct 1 ms 364 KB Output is correct
140 Correct 1 ms 364 KB Output is correct
141 Correct 1091 ms 70684 KB Output is correct
142 Correct 1088 ms 70312 KB Output is correct
143 Correct 1106 ms 70636 KB Output is correct
144 Correct 1118 ms 70508 KB Output is correct
145 Correct 1062 ms 70340 KB Output is correct
146 Correct 835 ms 66720 KB Output is correct
147 Correct 870 ms 67484 KB Output is correct
148 Correct 845 ms 67052 KB Output is correct
149 Correct 302 ms 17900 KB Output is correct
150 Correct 200 ms 15852 KB Output is correct
151 Correct 200 ms 15980 KB Output is correct
152 Correct 297 ms 17772 KB Output is correct
153 Correct 210 ms 15596 KB Output is correct
154 Correct 205 ms 15596 KB Output is correct
155 Correct 308 ms 17772 KB Output is correct