Submission #1002246

# Submission time Handle Problem Language Result Execution time Memory
1002246 2024-06-19T11:23:27 Z Whisper Fuel Station (NOI20_fuelstation) C++17
100 / 100
316 ms 35312 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define int long long
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (b); i >= (a); i --)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPD(i, n) for (int i = (n) - 1; i >= 0; --i)

#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)


constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*
    Phu Trong from Nguyen Tat Thanh High School for gifted student
*/

template <class X, class Y>
    bool minimize(X &x, const Y &y){
        X eps = 1e-9;
        if (x > y + eps) {x = y; return 1;}
        return 0;
    }

template <class X, class Y>
    bool maximize(X &x, const Y &y){
        X eps = 1e-9;
        if (x + eps < y) {x = y; return 1;}
        return 0;
    }
int N, K;
#define MAX     300005
struct Event{
    int X, A, B;
    Event(){}
    Event(int _X, int _A, int _B): X(_X), A(_A), B(_B){}

    bool operator < (const Event& oth) const{
        return B > oth.B;
    }
} A[MAX];

template <class T = vector<int>>
    T unique(T v){
        sort(v.begin(), v.end());
        v.resize(unique(v.begin(), v.end()) - v.begin());
        return v;
    }
template <class T = int>
    T find(T x, const vector<T>& v){
        return upper_bound(v.begin(), v.end(), x) - v.begin();
    }

template <class T = int> struct SegmentTree{
    int n;
    vector<T> st, lz;
    SegmentTree(int _n){
        this -> n = _n;
        st.resize((n << 2) + 5);
        lz.resize((n << 2) + 5);
    }

    void pushDown(int id){
        if (!lz[id]) return;
        st[id << 1] += lz[id];
        st[id << 1 | 1] += lz[id];
        lz[id << 1] += lz[id];
        lz[id << 1 | 1] += lz[id];
        lz[id] = 0;
    }
    void upd(int id, int l, int r, int u, int v, T val){
        if (u > r || v < l) return;
        if (u <= l && v >= r){
            st[id] += val; lz[id] += val;
            return;
        }
        int m = (l + r) >> 1;
        pushDown(id);
        upd(id << 1, l, m, u, v, val);
        upd(id << 1 | 1, m + 1, r, u, v, val);
        st[id] = min(st[id << 1], st[id << 1 | 1]);
    }
    void upd(int l, int r, T val){
        upd(1, 0, n, l, r, val);
    }
};

void process(void){
    cin >> N >> K;
    vector<Event> event;

    vector<int> pos;
    for (int i = 1; i <= N; ++i){
        int x, a, b; cin >> x >> a >> b;
        event.push_back(Event(x, a, b));
        pos.push_back(x);
    }
    event.push_back(Event(K, 0, 0));
    pos.push_back(0); pos.push_back(K);
    pos = unique(pos);

    N = (int)pos.size();
    SegmentTree<int> st(N);

    for (int i = 0; i < N; ++i){
        st.upd(i, i, -pos[i]);
    }

    sort(event.begin(), event.end());
    int ans = K;
    for (auto&x : event){
        int p = find(x.X, pos);
        st.upd(p, N, x.A);
        if (abs(st.st[1]) <= x.B){
            minimize(ans, abs(st.st[1]));
        }
    }
    cout << ans;
}

signed main(){
    #define name "Whisper"
    cin.tie(nullptr) -> sync_with_stdio(false);
    //freopen(name".inp", "r", stdin);
    //freopen(name".out", "w", stdout);

    process();
}




# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 150 ms 17116 KB Output is correct
2 Correct 157 ms 18164 KB Output is correct
3 Correct 152 ms 16772 KB Output is correct
4 Correct 116 ms 17144 KB Output is correct
5 Correct 115 ms 17476 KB Output is correct
6 Correct 149 ms 16844 KB Output is correct
7 Correct 150 ms 16888 KB Output is correct
8 Correct 115 ms 16884 KB Output is correct
9 Correct 155 ms 18420 KB Output is correct
10 Correct 113 ms 17528 KB Output is correct
11 Correct 155 ms 16892 KB Output is correct
12 Correct 112 ms 18160 KB Output is correct
13 Correct 150 ms 18420 KB Output is correct
14 Correct 153 ms 17704 KB Output is correct
15 Correct 116 ms 17656 KB Output is correct
16 Correct 154 ms 18420 KB Output is correct
17 Correct 117 ms 16928 KB Output is correct
18 Correct 155 ms 18008 KB Output is correct
19 Correct 117 ms 18584 KB Output is correct
20 Correct 172 ms 18420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 920 KB Output is correct
3 Correct 6 ms 1432 KB Output is correct
4 Correct 6 ms 1432 KB Output is correct
5 Correct 9 ms 1432 KB Output is correct
6 Correct 7 ms 1560 KB Output is correct
7 Correct 7 ms 1564 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 4 ms 920 KB Output is correct
15 Correct 5 ms 920 KB Output is correct
16 Correct 5 ms 920 KB Output is correct
17 Correct 5 ms 916 KB Output is correct
18 Correct 5 ms 1172 KB Output is correct
19 Correct 3 ms 920 KB Output is correct
20 Correct 4 ms 920 KB Output is correct
21 Correct 4 ms 920 KB Output is correct
22 Correct 3 ms 920 KB Output is correct
23 Correct 4 ms 920 KB Output is correct
24 Correct 3 ms 920 KB Output is correct
25 Correct 4 ms 920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 920 KB Output is correct
3 Correct 6 ms 1432 KB Output is correct
4 Correct 6 ms 1432 KB Output is correct
5 Correct 9 ms 1432 KB Output is correct
6 Correct 7 ms 1560 KB Output is correct
7 Correct 7 ms 1564 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 4 ms 920 KB Output is correct
15 Correct 5 ms 920 KB Output is correct
16 Correct 5 ms 920 KB Output is correct
17 Correct 5 ms 916 KB Output is correct
18 Correct 5 ms 1172 KB Output is correct
19 Correct 3 ms 920 KB Output is correct
20 Correct 4 ms 920 KB Output is correct
21 Correct 4 ms 920 KB Output is correct
22 Correct 3 ms 920 KB Output is correct
23 Correct 4 ms 920 KB Output is correct
24 Correct 3 ms 920 KB Output is correct
25 Correct 4 ms 920 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 107 ms 17624 KB Output is correct
28 Correct 133 ms 17660 KB Output is correct
29 Correct 126 ms 17928 KB Output is correct
30 Correct 147 ms 16892 KB Output is correct
31 Correct 146 ms 18420 KB Output is correct
32 Correct 144 ms 17656 KB Output is correct
33 Correct 0 ms 600 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 102 ms 18548 KB Output is correct
40 Correct 102 ms 18428 KB Output is correct
41 Correct 116 ms 18680 KB Output is correct
42 Correct 137 ms 18416 KB Output is correct
43 Correct 137 ms 17400 KB Output is correct
44 Correct 127 ms 18600 KB Output is correct
45 Correct 129 ms 18420 KB Output is correct
46 Correct 110 ms 17400 KB Output is correct
47 Correct 108 ms 18416 KB Output is correct
48 Correct 103 ms 16896 KB Output is correct
49 Correct 119 ms 17668 KB Output is correct
50 Correct 109 ms 17400 KB Output is correct
51 Correct 110 ms 17208 KB Output is correct
52 Correct 104 ms 17156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 3 ms 920 KB Output is correct
18 Correct 6 ms 1432 KB Output is correct
19 Correct 6 ms 1432 KB Output is correct
20 Correct 9 ms 1432 KB Output is correct
21 Correct 7 ms 1560 KB Output is correct
22 Correct 7 ms 1564 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 4 ms 920 KB Output is correct
30 Correct 5 ms 920 KB Output is correct
31 Correct 5 ms 920 KB Output is correct
32 Correct 5 ms 916 KB Output is correct
33 Correct 5 ms 1172 KB Output is correct
34 Correct 3 ms 920 KB Output is correct
35 Correct 4 ms 920 KB Output is correct
36 Correct 4 ms 920 KB Output is correct
37 Correct 3 ms 920 KB Output is correct
38 Correct 4 ms 920 KB Output is correct
39 Correct 3 ms 920 KB Output is correct
40 Correct 4 ms 920 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 5 ms 920 KB Output is correct
43 Correct 11 ms 1432 KB Output is correct
44 Correct 7 ms 1432 KB Output is correct
45 Correct 7 ms 1432 KB Output is correct
46 Correct 6 ms 1524 KB Output is correct
47 Correct 6 ms 1404 KB Output is correct
48 Correct 0 ms 344 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 600 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 7 ms 1432 KB Output is correct
55 Correct 7 ms 1432 KB Output is correct
56 Correct 7 ms 1428 KB Output is correct
57 Correct 7 ms 1432 KB Output is correct
58 Correct 7 ms 1432 KB Output is correct
59 Correct 4 ms 916 KB Output is correct
60 Correct 4 ms 920 KB Output is correct
61 Correct 4 ms 920 KB Output is correct
62 Correct 4 ms 920 KB Output is correct
63 Correct 5 ms 920 KB Output is correct
64 Correct 7 ms 1060 KB Output is correct
65 Correct 5 ms 920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 150 ms 17116 KB Output is correct
17 Correct 157 ms 18164 KB Output is correct
18 Correct 152 ms 16772 KB Output is correct
19 Correct 116 ms 17144 KB Output is correct
20 Correct 115 ms 17476 KB Output is correct
21 Correct 149 ms 16844 KB Output is correct
22 Correct 150 ms 16888 KB Output is correct
23 Correct 115 ms 16884 KB Output is correct
24 Correct 155 ms 18420 KB Output is correct
25 Correct 113 ms 17528 KB Output is correct
26 Correct 155 ms 16892 KB Output is correct
27 Correct 112 ms 18160 KB Output is correct
28 Correct 150 ms 18420 KB Output is correct
29 Correct 153 ms 17704 KB Output is correct
30 Correct 116 ms 17656 KB Output is correct
31 Correct 154 ms 18420 KB Output is correct
32 Correct 117 ms 16928 KB Output is correct
33 Correct 155 ms 18008 KB Output is correct
34 Correct 117 ms 18584 KB Output is correct
35 Correct 172 ms 18420 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 3 ms 920 KB Output is correct
38 Correct 6 ms 1432 KB Output is correct
39 Correct 6 ms 1432 KB Output is correct
40 Correct 9 ms 1432 KB Output is correct
41 Correct 7 ms 1560 KB Output is correct
42 Correct 7 ms 1564 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 4 ms 920 KB Output is correct
50 Correct 5 ms 920 KB Output is correct
51 Correct 5 ms 920 KB Output is correct
52 Correct 5 ms 916 KB Output is correct
53 Correct 5 ms 1172 KB Output is correct
54 Correct 3 ms 920 KB Output is correct
55 Correct 4 ms 920 KB Output is correct
56 Correct 4 ms 920 KB Output is correct
57 Correct 3 ms 920 KB Output is correct
58 Correct 4 ms 920 KB Output is correct
59 Correct 3 ms 920 KB Output is correct
60 Correct 4 ms 920 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 107 ms 17624 KB Output is correct
63 Correct 133 ms 17660 KB Output is correct
64 Correct 126 ms 17928 KB Output is correct
65 Correct 147 ms 16892 KB Output is correct
66 Correct 146 ms 18420 KB Output is correct
67 Correct 144 ms 17656 KB Output is correct
68 Correct 0 ms 600 KB Output is correct
69 Correct 0 ms 344 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 0 ms 348 KB Output is correct
74 Correct 102 ms 18548 KB Output is correct
75 Correct 102 ms 18428 KB Output is correct
76 Correct 116 ms 18680 KB Output is correct
77 Correct 137 ms 18416 KB Output is correct
78 Correct 137 ms 17400 KB Output is correct
79 Correct 127 ms 18600 KB Output is correct
80 Correct 129 ms 18420 KB Output is correct
81 Correct 110 ms 17400 KB Output is correct
82 Correct 108 ms 18416 KB Output is correct
83 Correct 103 ms 16896 KB Output is correct
84 Correct 119 ms 17668 KB Output is correct
85 Correct 109 ms 17400 KB Output is correct
86 Correct 110 ms 17208 KB Output is correct
87 Correct 104 ms 17156 KB Output is correct
88 Correct 0 ms 348 KB Output is correct
89 Correct 0 ms 348 KB Output is correct
90 Correct 0 ms 348 KB Output is correct
91 Correct 0 ms 348 KB Output is correct
92 Correct 0 ms 344 KB Output is correct
93 Correct 0 ms 348 KB Output is correct
94 Correct 0 ms 348 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 0 ms 348 KB Output is correct
98 Correct 0 ms 348 KB Output is correct
99 Correct 0 ms 348 KB Output is correct
100 Correct 0 ms 348 KB Output is correct
101 Correct 0 ms 348 KB Output is correct
102 Correct 0 ms 348 KB Output is correct
103 Correct 0 ms 348 KB Output is correct
104 Correct 5 ms 920 KB Output is correct
105 Correct 11 ms 1432 KB Output is correct
106 Correct 7 ms 1432 KB Output is correct
107 Correct 7 ms 1432 KB Output is correct
108 Correct 6 ms 1524 KB Output is correct
109 Correct 6 ms 1404 KB Output is correct
110 Correct 0 ms 344 KB Output is correct
111 Correct 0 ms 348 KB Output is correct
112 Correct 0 ms 348 KB Output is correct
113 Correct 0 ms 600 KB Output is correct
114 Correct 0 ms 348 KB Output is correct
115 Correct 0 ms 348 KB Output is correct
116 Correct 7 ms 1432 KB Output is correct
117 Correct 7 ms 1432 KB Output is correct
118 Correct 7 ms 1428 KB Output is correct
119 Correct 7 ms 1432 KB Output is correct
120 Correct 7 ms 1432 KB Output is correct
121 Correct 4 ms 916 KB Output is correct
122 Correct 4 ms 920 KB Output is correct
123 Correct 4 ms 920 KB Output is correct
124 Correct 4 ms 920 KB Output is correct
125 Correct 5 ms 920 KB Output is correct
126 Correct 7 ms 1060 KB Output is correct
127 Correct 5 ms 920 KB Output is correct
128 Correct 0 ms 348 KB Output is correct
129 Correct 167 ms 17864 KB Output is correct
130 Correct 276 ms 34924 KB Output is correct
131 Correct 277 ms 33772 KB Output is correct
132 Correct 284 ms 35016 KB Output is correct
133 Correct 316 ms 34440 KB Output is correct
134 Correct 285 ms 34128 KB Output is correct
135 Correct 0 ms 348 KB Output is correct
136 Correct 0 ms 348 KB Output is correct
137 Correct 0 ms 348 KB Output is correct
138 Correct 0 ms 348 KB Output is correct
139 Correct 0 ms 348 KB Output is correct
140 Correct 0 ms 348 KB Output is correct
141 Correct 277 ms 34176 KB Output is correct
142 Correct 287 ms 34544 KB Output is correct
143 Correct 285 ms 34876 KB Output is correct
144 Correct 308 ms 33620 KB Output is correct
145 Correct 264 ms 35312 KB Output is correct
146 Correct 302 ms 33004 KB Output is correct
147 Correct 237 ms 33516 KB Output is correct
148 Correct 251 ms 33260 KB Output is correct
149 Correct 162 ms 18388 KB Output is correct
150 Correct 116 ms 18676 KB Output is correct
151 Correct 114 ms 18168 KB Output is correct
152 Correct 162 ms 18716 KB Output is correct
153 Correct 127 ms 18172 KB Output is correct
154 Correct 124 ms 18580 KB Output is correct
155 Correct 162 ms 16784 KB Output is correct