Submission #1039994

# Submission time Handle Problem Language Result Execution time Memory
1039994 2024-07-31T13:33:43 Z underwaterkillerwhale Fuel Station (NOI20_fuelstation) C++17
100 / 100
534 ms 50252 KB
#include <bits/stdc++.h>
#define se              second
#define fs              first
#define mp              make_pair
#define pb              push_back
#define ll              long long
#define ii              pair<ll,ll>
#define ld              long double
#define SZ(v)           (int)v.size()
#define ALL(v)          v.begin(), v.end()
#define bit(msk, i)     ((msk >> i) & 1)
#define iter(id, v)     for(auto id : v)
#define rep(i,m,n)      for(int i=(m); i<=(n); i++)
#define reb(i,m,n)      for(int i=(m); i>=(n); i--)
using namespace std;

mt19937_64 rd(chrono :: steady_clock :: now().time_since_epoch().count());
ll Rand(ll l, ll r) { return uniform_int_distribution<ll> (l, r)(rd); }

const int N =3e5 + 7;
const int Mod = 1e9 + 7;
const int szBL = 240;
const int INF = 2e9;
const int BASE = 137;

struct Segment_Tree {
    struct Node {
        ll sum, pre;
    };
    int m;
    Node st[N << 2];

    void init (int n) {
        m = n;
    }

    Node mer (Node lf, Node rt) {
        Node cur;
        cur.pre = min(lf.pre, lf.sum + rt.pre);
        cur.sum = lf.sum + rt.sum;
        return cur;
    }

    void update (int id, int l, int r, int pos, ll val) {
        if (l > pos || r < pos) return;
        if (l == r) {
            st[id].sum += val;
            st[id].pre = min (0LL, st[id].sum);
            return;
        }
        int mid = l + r >> 1;
        update (id << 1, l, mid, pos, val);
        update (id << 1 | 1, mid + 1, r, pos, val);
        st[id] = mer(st[id << 1], st[id << 1 | 1]);
    }
    void update (int pos, ll val) {
        update (1, 1, m, pos, val);
    }
}ST;

struct Data {
    int X, a, b, id;
};

struct Data2 {
    int X, a, id;
};

int n, m, K, D;
Data a[N];
vector<Data2> events[N];
int cnt[N];

void solution () {
    cin >> n >> D;
    rep (i, 1, n) {
        cin >> a[i].X >> a[i].a >> a[i].b;
    }

    vector<int> valx, vals = {0, D};
    rep (i, 1, n) valx.push_back(a[i].X), vals.push_back(a[i].b);
    sort (ALL(vals));
    vals.resize(m = unique(ALL(vals)) - vals.begin());
    sort (ALL(valx));
    valx.resize(K = unique(ALL(valx)) - valx.begin());

    ST.init(K + 1);
    ST.update(K + 1, -D);
    rep (i, 1, n) {
        a[i].b = lower_bound(ALL(vals), a[i].b) - vals.begin();
        a[i].id = lower_bound(ALL(valx), a[i].X) - valx.begin() + 1;
        events[a[i].b].push_back({a[i].X, a[i].a, a[i].id});
        if (cnt[a[i].id] == 0) {
            ST.update (a[i].id, -a[i].X);
            ST.update (a[i].id + 1, a[i].X);
        }
        cnt[a[i].id]++;
        ST.update (a[i].id + 1, a[i].a);
    }
    ll res = INF;
    rep (i, 1, m - 1) {
        if (-ST.st[1].pre <= vals[i])
            res = min(res, -ST.st[1].pre);
        iter (&id, events[i]) {
            ST.update(id.id + 1, -id.a);
            --cnt[id.id];
            if (cnt[id.id] == 0) {
                ST.update (id.id, id.X);
                ST.update (id.id + 1, -id.X);
            }
        }
    }
    cout << res <<"\n";
}

#define file(name) freopen(name".inp", "r", stdin); \
freopen(name".out", "w", stdout);
/*
*/
int main () {
//    file("c");
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll num_Test = 1;
//    cin >> num_Test;
    while(num_Test--)
        solution();
}
/*
no bug challenge +2
more insight about dp0/1
*/

Compilation message

FuelStation.cpp: In member function 'void Segment_Tree::update(int, int, int, int, long long int)':
FuelStation.cpp:51:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   51 |         int mid = l + r >> 1;
      |                   ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7516 KB Output is correct
2 Correct 3 ms 7516 KB Output is correct
3 Correct 2 ms 7516 KB Output is correct
4 Correct 2 ms 7516 KB Output is correct
5 Correct 3 ms 7516 KB Output is correct
6 Correct 3 ms 7516 KB Output is correct
7 Correct 2 ms 7516 KB Output is correct
8 Correct 3 ms 7516 KB Output is correct
9 Correct 2 ms 7436 KB Output is correct
10 Correct 3 ms 7516 KB Output is correct
11 Correct 3 ms 7512 KB Output is correct
12 Correct 3 ms 7516 KB Output is correct
13 Correct 2 ms 7516 KB Output is correct
14 Correct 3 ms 7520 KB Output is correct
15 Correct 3 ms 7516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 172 ms 31044 KB Output is correct
2 Correct 167 ms 31180 KB Output is correct
3 Correct 168 ms 30896 KB Output is correct
4 Correct 111 ms 30640 KB Output is correct
5 Correct 119 ms 31144 KB Output is correct
6 Correct 164 ms 30544 KB Output is correct
7 Correct 161 ms 30368 KB Output is correct
8 Correct 122 ms 30636 KB Output is correct
9 Correct 164 ms 31736 KB Output is correct
10 Correct 110 ms 29872 KB Output is correct
11 Correct 160 ms 30524 KB Output is correct
12 Correct 117 ms 30600 KB Output is correct
13 Correct 175 ms 30380 KB Output is correct
14 Correct 172 ms 31204 KB Output is correct
15 Correct 115 ms 30632 KB Output is correct
16 Correct 169 ms 31916 KB Output is correct
17 Correct 117 ms 31244 KB Output is correct
18 Correct 173 ms 31056 KB Output is correct
19 Correct 113 ms 30640 KB Output is correct
20 Correct 163 ms 31144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7516 KB Output is correct
2 Correct 6 ms 8028 KB Output is correct
3 Correct 12 ms 8560 KB Output is correct
4 Correct 12 ms 8536 KB Output is correct
5 Correct 12 ms 8540 KB Output is correct
6 Correct 12 ms 8536 KB Output is correct
7 Correct 13 ms 8540 KB Output is correct
8 Correct 2 ms 7532 KB Output is correct
9 Correct 3 ms 7516 KB Output is correct
10 Correct 3 ms 7516 KB Output is correct
11 Correct 2 ms 7516 KB Output is correct
12 Correct 2 ms 7516 KB Output is correct
13 Correct 3 ms 7516 KB Output is correct
14 Correct 8 ms 8028 KB Output is correct
15 Correct 9 ms 8216 KB Output is correct
16 Correct 9 ms 8028 KB Output is correct
17 Correct 10 ms 8272 KB Output is correct
18 Correct 11 ms 8172 KB Output is correct
19 Correct 6 ms 8028 KB Output is correct
20 Correct 8 ms 8280 KB Output is correct
21 Correct 6 ms 8284 KB Output is correct
22 Correct 5 ms 8116 KB Output is correct
23 Correct 7 ms 8052 KB Output is correct
24 Correct 6 ms 8028 KB Output is correct
25 Correct 7 ms 8028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7516 KB Output is correct
2 Correct 6 ms 8028 KB Output is correct
3 Correct 12 ms 8560 KB Output is correct
4 Correct 12 ms 8536 KB Output is correct
5 Correct 12 ms 8540 KB Output is correct
6 Correct 12 ms 8536 KB Output is correct
7 Correct 13 ms 8540 KB Output is correct
8 Correct 2 ms 7532 KB Output is correct
9 Correct 3 ms 7516 KB Output is correct
10 Correct 3 ms 7516 KB Output is correct
11 Correct 2 ms 7516 KB Output is correct
12 Correct 2 ms 7516 KB Output is correct
13 Correct 3 ms 7516 KB Output is correct
14 Correct 8 ms 8028 KB Output is correct
15 Correct 9 ms 8216 KB Output is correct
16 Correct 9 ms 8028 KB Output is correct
17 Correct 10 ms 8272 KB Output is correct
18 Correct 11 ms 8172 KB Output is correct
19 Correct 6 ms 8028 KB Output is correct
20 Correct 8 ms 8280 KB Output is correct
21 Correct 6 ms 8284 KB Output is correct
22 Correct 5 ms 8116 KB Output is correct
23 Correct 7 ms 8052 KB Output is correct
24 Correct 6 ms 8028 KB Output is correct
25 Correct 7 ms 8028 KB Output is correct
26 Correct 2 ms 7516 KB Output is correct
27 Correct 118 ms 25568 KB Output is correct
28 Correct 163 ms 25008 KB Output is correct
29 Correct 162 ms 24728 KB Output is correct
30 Correct 158 ms 24748 KB Output is correct
31 Correct 180 ms 27072 KB Output is correct
32 Correct 177 ms 26796 KB Output is correct
33 Correct 3 ms 7512 KB Output is correct
34 Correct 2 ms 7516 KB Output is correct
35 Correct 2 ms 7516 KB Output is correct
36 Correct 3 ms 7516 KB Output is correct
37 Correct 2 ms 7516 KB Output is correct
38 Correct 3 ms 7516 KB Output is correct
39 Correct 135 ms 24816 KB Output is correct
40 Correct 138 ms 25032 KB Output is correct
41 Correct 139 ms 25008 KB Output is correct
42 Correct 140 ms 24996 KB Output is correct
43 Correct 167 ms 24956 KB Output is correct
44 Correct 157 ms 23456 KB Output is correct
45 Correct 137 ms 26412 KB Output is correct
46 Correct 133 ms 24232 KB Output is correct
47 Correct 118 ms 28076 KB Output is correct
48 Correct 104 ms 28080 KB Output is correct
49 Correct 141 ms 24748 KB Output is correct
50 Correct 125 ms 25152 KB Output is correct
51 Correct 126 ms 25264 KB Output is correct
52 Correct 120 ms 25072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7516 KB Output is correct
2 Correct 3 ms 7516 KB Output is correct
3 Correct 2 ms 7516 KB Output is correct
4 Correct 2 ms 7516 KB Output is correct
5 Correct 3 ms 7516 KB Output is correct
6 Correct 3 ms 7516 KB Output is correct
7 Correct 2 ms 7516 KB Output is correct
8 Correct 3 ms 7516 KB Output is correct
9 Correct 2 ms 7436 KB Output is correct
10 Correct 3 ms 7516 KB Output is correct
11 Correct 3 ms 7512 KB Output is correct
12 Correct 3 ms 7516 KB Output is correct
13 Correct 2 ms 7516 KB Output is correct
14 Correct 3 ms 7520 KB Output is correct
15 Correct 3 ms 7516 KB Output is correct
16 Correct 2 ms 7512 KB Output is correct
17 Correct 2 ms 7516 KB Output is correct
18 Correct 3 ms 7512 KB Output is correct
19 Correct 3 ms 7516 KB Output is correct
20 Correct 3 ms 7516 KB Output is correct
21 Correct 3 ms 7516 KB Output is correct
22 Correct 4 ms 7520 KB Output is correct
23 Correct 3 ms 7768 KB Output is correct
24 Correct 3 ms 7772 KB Output is correct
25 Correct 2 ms 7516 KB Output is correct
26 Correct 3 ms 7516 KB Output is correct
27 Correct 3 ms 7516 KB Output is correct
28 Correct 3 ms 7516 KB Output is correct
29 Correct 3 ms 7392 KB Output is correct
30 Correct 3 ms 7516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7516 KB Output is correct
2 Correct 3 ms 7516 KB Output is correct
3 Correct 2 ms 7516 KB Output is correct
4 Correct 2 ms 7516 KB Output is correct
5 Correct 3 ms 7516 KB Output is correct
6 Correct 3 ms 7516 KB Output is correct
7 Correct 2 ms 7516 KB Output is correct
8 Correct 3 ms 7516 KB Output is correct
9 Correct 2 ms 7436 KB Output is correct
10 Correct 3 ms 7516 KB Output is correct
11 Correct 3 ms 7512 KB Output is correct
12 Correct 3 ms 7516 KB Output is correct
13 Correct 2 ms 7516 KB Output is correct
14 Correct 3 ms 7520 KB Output is correct
15 Correct 3 ms 7516 KB Output is correct
16 Correct 2 ms 7516 KB Output is correct
17 Correct 6 ms 8028 KB Output is correct
18 Correct 12 ms 8560 KB Output is correct
19 Correct 12 ms 8536 KB Output is correct
20 Correct 12 ms 8540 KB Output is correct
21 Correct 12 ms 8536 KB Output is correct
22 Correct 13 ms 8540 KB Output is correct
23 Correct 2 ms 7532 KB Output is correct
24 Correct 3 ms 7516 KB Output is correct
25 Correct 3 ms 7516 KB Output is correct
26 Correct 2 ms 7516 KB Output is correct
27 Correct 2 ms 7516 KB Output is correct
28 Correct 3 ms 7516 KB Output is correct
29 Correct 8 ms 8028 KB Output is correct
30 Correct 9 ms 8216 KB Output is correct
31 Correct 9 ms 8028 KB Output is correct
32 Correct 10 ms 8272 KB Output is correct
33 Correct 11 ms 8172 KB Output is correct
34 Correct 6 ms 8028 KB Output is correct
35 Correct 8 ms 8280 KB Output is correct
36 Correct 6 ms 8284 KB Output is correct
37 Correct 5 ms 8116 KB Output is correct
38 Correct 7 ms 8052 KB Output is correct
39 Correct 6 ms 8028 KB Output is correct
40 Correct 7 ms 8028 KB Output is correct
41 Correct 3 ms 7516 KB Output is correct
42 Correct 6 ms 8172 KB Output is correct
43 Correct 15 ms 8808 KB Output is correct
44 Correct 17 ms 8924 KB Output is correct
45 Correct 15 ms 8908 KB Output is correct
46 Correct 14 ms 8796 KB Output is correct
47 Correct 14 ms 8764 KB Output is correct
48 Correct 3 ms 7516 KB Output is correct
49 Correct 3 ms 7516 KB Output is correct
50 Correct 3 ms 7516 KB Output is correct
51 Correct 3 ms 7424 KB Output is correct
52 Correct 4 ms 7516 KB Output is correct
53 Correct 3 ms 7516 KB Output is correct
54 Correct 14 ms 8924 KB Output is correct
55 Correct 14 ms 8792 KB Output is correct
56 Correct 14 ms 8796 KB Output is correct
57 Correct 14 ms 8932 KB Output is correct
58 Correct 14 ms 9052 KB Output is correct
59 Correct 7 ms 8024 KB Output is correct
60 Correct 8 ms 8284 KB Output is correct
61 Correct 7 ms 8424 KB Output is correct
62 Correct 7 ms 8284 KB Output is correct
63 Correct 7 ms 8112 KB Output is correct
64 Correct 9 ms 8116 KB Output is correct
65 Correct 7 ms 8024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7516 KB Output is correct
2 Correct 3 ms 7516 KB Output is correct
3 Correct 2 ms 7516 KB Output is correct
4 Correct 2 ms 7516 KB Output is correct
5 Correct 3 ms 7516 KB Output is correct
6 Correct 3 ms 7516 KB Output is correct
7 Correct 2 ms 7516 KB Output is correct
8 Correct 3 ms 7516 KB Output is correct
9 Correct 2 ms 7436 KB Output is correct
10 Correct 3 ms 7516 KB Output is correct
11 Correct 3 ms 7512 KB Output is correct
12 Correct 3 ms 7516 KB Output is correct
13 Correct 2 ms 7516 KB Output is correct
14 Correct 3 ms 7520 KB Output is correct
15 Correct 3 ms 7516 KB Output is correct
16 Correct 172 ms 31044 KB Output is correct
17 Correct 167 ms 31180 KB Output is correct
18 Correct 168 ms 30896 KB Output is correct
19 Correct 111 ms 30640 KB Output is correct
20 Correct 119 ms 31144 KB Output is correct
21 Correct 164 ms 30544 KB Output is correct
22 Correct 161 ms 30368 KB Output is correct
23 Correct 122 ms 30636 KB Output is correct
24 Correct 164 ms 31736 KB Output is correct
25 Correct 110 ms 29872 KB Output is correct
26 Correct 160 ms 30524 KB Output is correct
27 Correct 117 ms 30600 KB Output is correct
28 Correct 175 ms 30380 KB Output is correct
29 Correct 172 ms 31204 KB Output is correct
30 Correct 115 ms 30632 KB Output is correct
31 Correct 169 ms 31916 KB Output is correct
32 Correct 117 ms 31244 KB Output is correct
33 Correct 173 ms 31056 KB Output is correct
34 Correct 113 ms 30640 KB Output is correct
35 Correct 163 ms 31144 KB Output is correct
36 Correct 2 ms 7516 KB Output is correct
37 Correct 6 ms 8028 KB Output is correct
38 Correct 12 ms 8560 KB Output is correct
39 Correct 12 ms 8536 KB Output is correct
40 Correct 12 ms 8540 KB Output is correct
41 Correct 12 ms 8536 KB Output is correct
42 Correct 13 ms 8540 KB Output is correct
43 Correct 2 ms 7532 KB Output is correct
44 Correct 3 ms 7516 KB Output is correct
45 Correct 3 ms 7516 KB Output is correct
46 Correct 2 ms 7516 KB Output is correct
47 Correct 2 ms 7516 KB Output is correct
48 Correct 3 ms 7516 KB Output is correct
49 Correct 8 ms 8028 KB Output is correct
50 Correct 9 ms 8216 KB Output is correct
51 Correct 9 ms 8028 KB Output is correct
52 Correct 10 ms 8272 KB Output is correct
53 Correct 11 ms 8172 KB Output is correct
54 Correct 6 ms 8028 KB Output is correct
55 Correct 8 ms 8280 KB Output is correct
56 Correct 6 ms 8284 KB Output is correct
57 Correct 5 ms 8116 KB Output is correct
58 Correct 7 ms 8052 KB Output is correct
59 Correct 6 ms 8028 KB Output is correct
60 Correct 7 ms 8028 KB Output is correct
61 Correct 2 ms 7516 KB Output is correct
62 Correct 118 ms 25568 KB Output is correct
63 Correct 163 ms 25008 KB Output is correct
64 Correct 162 ms 24728 KB Output is correct
65 Correct 158 ms 24748 KB Output is correct
66 Correct 180 ms 27072 KB Output is correct
67 Correct 177 ms 26796 KB Output is correct
68 Correct 3 ms 7512 KB Output is correct
69 Correct 2 ms 7516 KB Output is correct
70 Correct 2 ms 7516 KB Output is correct
71 Correct 3 ms 7516 KB Output is correct
72 Correct 2 ms 7516 KB Output is correct
73 Correct 3 ms 7516 KB Output is correct
74 Correct 135 ms 24816 KB Output is correct
75 Correct 138 ms 25032 KB Output is correct
76 Correct 139 ms 25008 KB Output is correct
77 Correct 140 ms 24996 KB Output is correct
78 Correct 167 ms 24956 KB Output is correct
79 Correct 157 ms 23456 KB Output is correct
80 Correct 137 ms 26412 KB Output is correct
81 Correct 133 ms 24232 KB Output is correct
82 Correct 118 ms 28076 KB Output is correct
83 Correct 104 ms 28080 KB Output is correct
84 Correct 141 ms 24748 KB Output is correct
85 Correct 125 ms 25152 KB Output is correct
86 Correct 126 ms 25264 KB Output is correct
87 Correct 120 ms 25072 KB Output is correct
88 Correct 2 ms 7512 KB Output is correct
89 Correct 2 ms 7516 KB Output is correct
90 Correct 3 ms 7512 KB Output is correct
91 Correct 3 ms 7516 KB Output is correct
92 Correct 3 ms 7516 KB Output is correct
93 Correct 3 ms 7516 KB Output is correct
94 Correct 4 ms 7520 KB Output is correct
95 Correct 3 ms 7768 KB Output is correct
96 Correct 3 ms 7772 KB Output is correct
97 Correct 2 ms 7516 KB Output is correct
98 Correct 3 ms 7516 KB Output is correct
99 Correct 3 ms 7516 KB Output is correct
100 Correct 3 ms 7516 KB Output is correct
101 Correct 3 ms 7392 KB Output is correct
102 Correct 3 ms 7516 KB Output is correct
103 Correct 3 ms 7516 KB Output is correct
104 Correct 6 ms 8172 KB Output is correct
105 Correct 15 ms 8808 KB Output is correct
106 Correct 17 ms 8924 KB Output is correct
107 Correct 15 ms 8908 KB Output is correct
108 Correct 14 ms 8796 KB Output is correct
109 Correct 14 ms 8764 KB Output is correct
110 Correct 3 ms 7516 KB Output is correct
111 Correct 3 ms 7516 KB Output is correct
112 Correct 3 ms 7516 KB Output is correct
113 Correct 3 ms 7424 KB Output is correct
114 Correct 4 ms 7516 KB Output is correct
115 Correct 3 ms 7516 KB Output is correct
116 Correct 14 ms 8924 KB Output is correct
117 Correct 14 ms 8792 KB Output is correct
118 Correct 14 ms 8796 KB Output is correct
119 Correct 14 ms 8932 KB Output is correct
120 Correct 14 ms 9052 KB Output is correct
121 Correct 7 ms 8024 KB Output is correct
122 Correct 8 ms 8284 KB Output is correct
123 Correct 7 ms 8424 KB Output is correct
124 Correct 7 ms 8284 KB Output is correct
125 Correct 7 ms 8112 KB Output is correct
126 Correct 9 ms 8116 KB Output is correct
127 Correct 7 ms 8024 KB Output is correct
128 Correct 3 ms 7516 KB Output is correct
129 Correct 209 ms 27908 KB Output is correct
130 Correct 507 ms 49580 KB Output is correct
131 Correct 513 ms 50088 KB Output is correct
132 Correct 505 ms 49588 KB Output is correct
133 Correct 508 ms 49496 KB Output is correct
134 Correct 499 ms 49996 KB Output is correct
135 Correct 3 ms 7516 KB Output is correct
136 Correct 2 ms 7520 KB Output is correct
137 Correct 3 ms 7516 KB Output is correct
138 Correct 3 ms 7516 KB Output is correct
139 Correct 2 ms 7516 KB Output is correct
140 Correct 3 ms 7516 KB Output is correct
141 Correct 512 ms 50252 KB Output is correct
142 Correct 534 ms 49836 KB Output is correct
143 Correct 504 ms 50092 KB Output is correct
144 Correct 510 ms 50200 KB Output is correct
145 Correct 485 ms 50088 KB Output is correct
146 Correct 442 ms 48308 KB Output is correct
147 Correct 467 ms 48816 KB Output is correct
148 Correct 450 ms 48560 KB Output is correct
149 Correct 203 ms 28728 KB Output is correct
150 Correct 115 ms 30452 KB Output is correct
151 Correct 116 ms 30636 KB Output is correct
152 Correct 181 ms 29812 KB Output is correct
153 Correct 154 ms 28080 KB Output is correct
154 Correct 134 ms 29356 KB Output is correct
155 Correct 201 ms 28592 KB Output is correct