Submission #331451

# Submission time Handle Problem Language Result Execution time Memory
331451 2020-11-28T14:13:54 Z two_sides Fuel Station (NOI20_fuelstation) C++17
100 / 100
618 ms 36460 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const int N = 3e5 + 5;

struct station {
    int x, a, b;
};

struct segtree {
    static const ll INF = LLONG_MAX;

    vector <ll> val, tag;
    int lo, hi, n; ll v;

    segtree(int n): n(n) {
        val.resize(n * 4 + 10);
        tag.resize(n * 4 + 10);
    }

    void push_tag(int i, ll tg) {
        val[i] += tg; tag[i] += tg;
    }

    void push_down(int i) {
        push_tag(i * 2, tag[i]);
        push_tag(i * 2 + 1, tag[i]);
        tag[i] = 0;
    }

    void update(int i, int l, int r) {
        if (l > hi || r < lo) return;
        if (l >= lo && r <= hi)
            return push_tag(i, v);
        push_down(i);
        int m = (l + r) / 2;
        update(i * 2, l, m);
        update(i * 2 + 1, m + 1, r);
        val[i] = min(val[i * 2],
        val[i * 2 + 1]);
    }

    void query(int i, int l, int r) {
        if (l > hi || r < lo) return;
        if (l >= lo && r <= hi) {
            v = min(v, val[i]); return;
        }
        push_down(i);
        int m = (l + r) / 2;
        query(i * 2, l, m);
        query(i * 2 + 1, m + 1, r);
    }

    void update(int lo, int hi, ll v) {
        if (lo > hi) return;
        this->lo = lo; this->hi = hi;
        this->v = v; update(1, 0, n);
    }

    ll query(int lo, int hi) {
        if (lo > hi) return INF;
        this->lo = lo; this->hi = hi;
        v = INF; query(1, 0, n);
        return v;
    }
};

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int n, d; cin >> n >> d;
    vector <station> ff(n);
    vector <int> nxt(n + 1);
    segtree st(n);
    for (station &s : ff)
        cin >> s.x >> s.a >> s.b;
    ff.push_back({d, 0, d});
    sort(ff.begin(), ff.end(),
    [](station p, station q) {
        return p.x < q.x;
    });
    int j = 0;
    for (int i = 0; i <= n; i++) {
        while (j < n &&
        ff[j].x == ff[i].x) j++;
        nxt[i] = j;
    }
    vector <int> od(n + 1);
    iota(od.begin(), od.end(), 0);
    sort(od.begin(), od.end(),
    [&](int i, int j) {
        return ff[i].b < ff[j].b;
    });
    j = 0;
    for (int i = 0; i <= n; i++) {
        st.update(i, i, -ll(ff[i].x));
        st.update(nxt[i], n, ll(ff[i].a));
    }
    for (int i = 0; i <= n; i++) {
        st.update(0, n, ll(ff[od[i]].b)
        - (i ? ff[od[i - 1]].b : 0));
        while (j < i &&
        ff[od[j]].b < ff[od[i]].b) {
            st.update(nxt[od[j]], n,
            -ll(ff[od[j]].a)); j++;
        }
        if (st.val[1] >= 0) {
            cout << ff[od[i]].b
            - st.val[1]; 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 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 384 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 384 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 356 ms 27372 KB Output is correct
2 Correct 370 ms 35892 KB Output is correct
3 Correct 362 ms 35692 KB Output is correct
4 Correct 361 ms 35820 KB Output is correct
5 Correct 347 ms 36332 KB Output is correct
6 Correct 355 ms 35180 KB Output is correct
7 Correct 353 ms 35180 KB Output is correct
8 Correct 349 ms 35692 KB Output is correct
9 Correct 349 ms 36332 KB Output is correct
10 Correct 354 ms 35052 KB Output is correct
11 Correct 358 ms 35052 KB Output is correct
12 Correct 356 ms 35892 KB Output is correct
13 Correct 371 ms 35180 KB Output is correct
14 Correct 377 ms 35820 KB Output is correct
15 Correct 349 ms 35764 KB Output is correct
16 Correct 349 ms 36332 KB Output is correct
17 Correct 363 ms 36460 KB Output is correct
18 Correct 365 ms 35820 KB Output is correct
19 Correct 342 ms 35692 KB Output is correct
20 Correct 349 ms 35692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 9 ms 1260 KB Output is correct
3 Correct 10 ms 1260 KB Output is correct
4 Correct 10 ms 1516 KB Output is correct
5 Correct 10 ms 1388 KB Output is correct
6 Correct 10 ms 1388 KB Output is correct
7 Correct 10 ms 1388 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 13 ms 1388 KB Output is correct
15 Correct 12 ms 1388 KB Output is correct
16 Correct 13 ms 1388 KB Output is correct
17 Correct 14 ms 1516 KB Output is correct
18 Correct 13 ms 1388 KB Output is correct
19 Correct 10 ms 1388 KB Output is correct
20 Correct 10 ms 1388 KB Output is correct
21 Correct 11 ms 1388 KB Output is correct
22 Correct 9 ms 1388 KB Output is correct
23 Correct 9 ms 1388 KB Output is correct
24 Correct 9 ms 1388 KB Output is correct
25 Correct 9 ms 1388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 9 ms 1260 KB Output is correct
3 Correct 10 ms 1260 KB Output is correct
4 Correct 10 ms 1516 KB Output is correct
5 Correct 10 ms 1388 KB Output is correct
6 Correct 10 ms 1388 KB Output is correct
7 Correct 10 ms 1388 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 13 ms 1388 KB Output is correct
15 Correct 12 ms 1388 KB Output is correct
16 Correct 13 ms 1388 KB Output is correct
17 Correct 14 ms 1516 KB Output is correct
18 Correct 13 ms 1388 KB Output is correct
19 Correct 10 ms 1388 KB Output is correct
20 Correct 10 ms 1388 KB Output is correct
21 Correct 11 ms 1388 KB Output is correct
22 Correct 9 ms 1388 KB Output is correct
23 Correct 9 ms 1388 KB Output is correct
24 Correct 9 ms 1388 KB Output is correct
25 Correct 9 ms 1388 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 333 ms 31596 KB Output is correct
28 Correct 339 ms 31468 KB Output is correct
29 Correct 332 ms 31084 KB Output is correct
30 Correct 339 ms 31084 KB Output is correct
31 Correct 338 ms 31724 KB Output is correct
32 Correct 350 ms 31468 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 529 ms 31724 KB Output is correct
40 Correct 528 ms 31724 KB Output is correct
41 Correct 540 ms 31724 KB Output is correct
42 Correct 506 ms 31724 KB Output is correct
43 Correct 558 ms 31724 KB Output is correct
44 Correct 399 ms 31284 KB Output is correct
45 Correct 417 ms 30828 KB Output is correct
46 Correct 333 ms 31764 KB Output is correct
47 Correct 338 ms 33132 KB Output is correct
48 Correct 350 ms 33260 KB Output is correct
49 Correct 350 ms 30956 KB Output is correct
50 Correct 339 ms 31468 KB Output is correct
51 Correct 333 ms 31468 KB Output is correct
52 Correct 334 ms 31212 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 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 384 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 384 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 0 ms 364 KB Output is correct
17 Correct 0 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 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 384 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 384 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 9 ms 1260 KB Output is correct
18 Correct 10 ms 1260 KB Output is correct
19 Correct 10 ms 1516 KB Output is correct
20 Correct 10 ms 1388 KB Output is correct
21 Correct 10 ms 1388 KB Output is correct
22 Correct 10 ms 1388 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 13 ms 1388 KB Output is correct
30 Correct 12 ms 1388 KB Output is correct
31 Correct 13 ms 1388 KB Output is correct
32 Correct 14 ms 1516 KB Output is correct
33 Correct 13 ms 1388 KB Output is correct
34 Correct 10 ms 1388 KB Output is correct
35 Correct 10 ms 1388 KB Output is correct
36 Correct 11 ms 1388 KB Output is correct
37 Correct 9 ms 1388 KB Output is correct
38 Correct 9 ms 1388 KB Output is correct
39 Correct 9 ms 1388 KB Output is correct
40 Correct 9 ms 1388 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 10 ms 1516 KB Output is correct
43 Correct 11 ms 1516 KB Output is correct
44 Correct 11 ms 1516 KB Output is correct
45 Correct 13 ms 1536 KB Output is correct
46 Correct 11 ms 1516 KB Output is correct
47 Correct 11 ms 1516 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 13 ms 1516 KB Output is correct
55 Correct 12 ms 1516 KB Output is correct
56 Correct 14 ms 1516 KB Output is correct
57 Correct 13 ms 1516 KB Output is correct
58 Correct 13 ms 1516 KB Output is correct
59 Correct 13 ms 1516 KB Output is correct
60 Correct 12 ms 1516 KB Output is correct
61 Correct 10 ms 1516 KB Output is correct
62 Correct 11 ms 1516 KB Output is correct
63 Correct 11 ms 1516 KB Output is correct
64 Correct 11 ms 1516 KB Output is correct
65 Correct 10 ms 1516 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 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 384 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 384 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 356 ms 27372 KB Output is correct
17 Correct 370 ms 35892 KB Output is correct
18 Correct 362 ms 35692 KB Output is correct
19 Correct 361 ms 35820 KB Output is correct
20 Correct 347 ms 36332 KB Output is correct
21 Correct 355 ms 35180 KB Output is correct
22 Correct 353 ms 35180 KB Output is correct
23 Correct 349 ms 35692 KB Output is correct
24 Correct 349 ms 36332 KB Output is correct
25 Correct 354 ms 35052 KB Output is correct
26 Correct 358 ms 35052 KB Output is correct
27 Correct 356 ms 35892 KB Output is correct
28 Correct 371 ms 35180 KB Output is correct
29 Correct 377 ms 35820 KB Output is correct
30 Correct 349 ms 35764 KB Output is correct
31 Correct 349 ms 36332 KB Output is correct
32 Correct 363 ms 36460 KB Output is correct
33 Correct 365 ms 35820 KB Output is correct
34 Correct 342 ms 35692 KB Output is correct
35 Correct 349 ms 35692 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 9 ms 1260 KB Output is correct
38 Correct 10 ms 1260 KB Output is correct
39 Correct 10 ms 1516 KB Output is correct
40 Correct 10 ms 1388 KB Output is correct
41 Correct 10 ms 1388 KB Output is correct
42 Correct 10 ms 1388 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 13 ms 1388 KB Output is correct
50 Correct 12 ms 1388 KB Output is correct
51 Correct 13 ms 1388 KB Output is correct
52 Correct 14 ms 1516 KB Output is correct
53 Correct 13 ms 1388 KB Output is correct
54 Correct 10 ms 1388 KB Output is correct
55 Correct 10 ms 1388 KB Output is correct
56 Correct 11 ms 1388 KB Output is correct
57 Correct 9 ms 1388 KB Output is correct
58 Correct 9 ms 1388 KB Output is correct
59 Correct 9 ms 1388 KB Output is correct
60 Correct 9 ms 1388 KB Output is correct
61 Correct 1 ms 364 KB Output is correct
62 Correct 333 ms 31596 KB Output is correct
63 Correct 339 ms 31468 KB Output is correct
64 Correct 332 ms 31084 KB Output is correct
65 Correct 339 ms 31084 KB Output is correct
66 Correct 338 ms 31724 KB Output is correct
67 Correct 350 ms 31468 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 529 ms 31724 KB Output is correct
75 Correct 528 ms 31724 KB Output is correct
76 Correct 540 ms 31724 KB Output is correct
77 Correct 506 ms 31724 KB Output is correct
78 Correct 558 ms 31724 KB Output is correct
79 Correct 399 ms 31284 KB Output is correct
80 Correct 417 ms 30828 KB Output is correct
81 Correct 333 ms 31764 KB Output is correct
82 Correct 338 ms 33132 KB Output is correct
83 Correct 350 ms 33260 KB Output is correct
84 Correct 350 ms 30956 KB Output is correct
85 Correct 339 ms 31468 KB Output is correct
86 Correct 333 ms 31468 KB Output is correct
87 Correct 334 ms 31212 KB Output is correct
88 Correct 0 ms 364 KB Output is correct
89 Correct 0 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 10 ms 1516 KB Output is correct
105 Correct 11 ms 1516 KB Output is correct
106 Correct 11 ms 1516 KB Output is correct
107 Correct 13 ms 1536 KB Output is correct
108 Correct 11 ms 1516 KB Output is correct
109 Correct 11 ms 1516 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 13 ms 1516 KB Output is correct
117 Correct 12 ms 1516 KB Output is correct
118 Correct 14 ms 1516 KB Output is correct
119 Correct 13 ms 1516 KB Output is correct
120 Correct 13 ms 1516 KB Output is correct
121 Correct 13 ms 1516 KB Output is correct
122 Correct 12 ms 1516 KB Output is correct
123 Correct 10 ms 1516 KB Output is correct
124 Correct 11 ms 1516 KB Output is correct
125 Correct 11 ms 1516 KB Output is correct
126 Correct 11 ms 1516 KB Output is correct
127 Correct 10 ms 1516 KB Output is correct
128 Correct 1 ms 364 KB Output is correct
129 Correct 381 ms 34856 KB Output is correct
130 Correct 387 ms 35436 KB Output is correct
131 Correct 412 ms 36076 KB Output is correct
132 Correct 397 ms 35436 KB Output is correct
133 Correct 396 ms 35436 KB Output is correct
134 Correct 393 ms 36076 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 512 KB Output is correct
139 Correct 1 ms 492 KB Output is correct
140 Correct 1 ms 364 KB Output is correct
141 Correct 600 ms 36076 KB Output is correct
142 Correct 618 ms 35692 KB Output is correct
143 Correct 567 ms 36076 KB Output is correct
144 Correct 600 ms 36076 KB Output is correct
145 Correct 603 ms 36096 KB Output is correct
146 Correct 515 ms 34284 KB Output is correct
147 Correct 461 ms 35052 KB Output is correct
148 Correct 472 ms 34540 KB Output is correct
149 Correct 369 ms 35436 KB Output is correct
150 Correct 342 ms 35692 KB Output is correct
151 Correct 344 ms 35692 KB Output is correct
152 Correct 382 ms 35436 KB Output is correct
153 Correct 373 ms 35308 KB Output is correct
154 Correct 357 ms 35436 KB Output is correct
155 Correct 372 ms 35436 KB Output is correct