Submission #1002248

# Submission time Handle Problem Language Result Execution time Memory
1002248 2024-06-19T11:28:00 Z vjudge1 Fuel Station (NOI20_fuelstation) C++17
100 / 100
272 ms 35104 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);
        //Let's assume F <= x.B
        if (abs(st.st[1]) <= x.B){
            //if F is satisfy  we update the answer
            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 348 KB Output is correct
11 Correct 0 ms 392 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 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 157 ms 18684 KB Output is correct
2 Correct 150 ms 17148 KB Output is correct
3 Correct 160 ms 17492 KB Output is correct
4 Correct 114 ms 17400 KB Output is correct
5 Correct 119 ms 18680 KB Output is correct
6 Correct 151 ms 17660 KB Output is correct
7 Correct 146 ms 16892 KB Output is correct
8 Correct 116 ms 17900 KB Output is correct
9 Correct 157 ms 18684 KB Output is correct
10 Correct 112 ms 16964 KB Output is correct
11 Correct 148 ms 17824 KB Output is correct
12 Correct 110 ms 17904 KB Output is correct
13 Correct 153 ms 18676 KB Output is correct
14 Correct 187 ms 17268 KB Output is correct
15 Correct 122 ms 17144 KB Output is correct
16 Correct 149 ms 18584 KB Output is correct
17 Correct 110 ms 17400 KB Output is correct
18 Correct 133 ms 17908 KB Output is correct
19 Correct 107 ms 17912 KB Output is correct
20 Correct 155 ms 17320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 6 ms 1432 KB Output is correct
6 Correct 6 ms 1564 KB Output is correct
7 Correct 6 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 5 ms 920 KB Output is correct
15 Correct 4 ms 920 KB Output is correct
16 Correct 5 ms 920 KB Output is correct
17 Correct 6 ms 920 KB Output is correct
18 Correct 5 ms 920 KB Output is correct
19 Correct 4 ms 920 KB Output is correct
20 Correct 6 ms 1076 KB Output is correct
21 Correct 4 ms 920 KB Output is correct
22 Correct 3 ms 920 KB Output is correct
23 Correct 3 ms 920 KB Output is correct
24 Correct 4 ms 916 KB Output is correct
25 Correct 4 ms 920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 6 ms 1432 KB Output is correct
6 Correct 6 ms 1564 KB Output is correct
7 Correct 6 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 5 ms 920 KB Output is correct
15 Correct 4 ms 920 KB Output is correct
16 Correct 5 ms 920 KB Output is correct
17 Correct 6 ms 920 KB Output is correct
18 Correct 5 ms 920 KB Output is correct
19 Correct 4 ms 920 KB Output is correct
20 Correct 6 ms 1076 KB Output is correct
21 Correct 4 ms 920 KB Output is correct
22 Correct 3 ms 920 KB Output is correct
23 Correct 3 ms 920 KB Output is correct
24 Correct 4 ms 916 KB Output is correct
25 Correct 4 ms 920 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 113 ms 17460 KB Output is correct
28 Correct 138 ms 17156 KB Output is correct
29 Correct 144 ms 17924 KB Output is correct
30 Correct 135 ms 17148 KB Output is correct
31 Correct 138 ms 17132 KB Output is correct
32 Correct 140 ms 17928 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 344 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 114 ms 16848 KB Output is correct
40 Correct 117 ms 17156 KB Output is correct
41 Correct 117 ms 17400 KB Output is correct
42 Correct 117 ms 18224 KB Output is correct
43 Correct 136 ms 18696 KB Output is correct
44 Correct 142 ms 17152 KB Output is correct
45 Correct 131 ms 18180 KB Output is correct
46 Correct 110 ms 17920 KB Output is correct
47 Correct 107 ms 17660 KB Output is correct
48 Correct 107 ms 17404 KB Output is correct
49 Correct 118 ms 17148 KB Output is correct
50 Correct 104 ms 17144 KB Output is correct
51 Correct 111 ms 17148 KB Output is correct
52 Correct 106 ms 17412 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 348 KB Output is correct
11 Correct 0 ms 392 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 0 ms 348 KB Output is correct
16 Correct 0 ms 344 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 348 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 348 KB Output is correct
11 Correct 0 ms 392 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 0 ms 348 KB Output is correct
16 Correct 1 ms 344 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 6 ms 1432 KB Output is correct
21 Correct 6 ms 1564 KB Output is correct
22 Correct 6 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 5 ms 920 KB Output is correct
30 Correct 4 ms 920 KB Output is correct
31 Correct 5 ms 920 KB Output is correct
32 Correct 6 ms 920 KB Output is correct
33 Correct 5 ms 920 KB Output is correct
34 Correct 4 ms 920 KB Output is correct
35 Correct 6 ms 1076 KB Output is correct
36 Correct 4 ms 920 KB Output is correct
37 Correct 3 ms 920 KB Output is correct
38 Correct 3 ms 920 KB Output is correct
39 Correct 4 ms 916 KB Output is correct
40 Correct 4 ms 920 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 4 ms 920 KB Output is correct
43 Correct 7 ms 1560 KB Output is correct
44 Correct 7 ms 1428 KB Output is correct
45 Correct 7 ms 1436 KB Output is correct
46 Correct 7 ms 1432 KB Output is correct
47 Correct 7 ms 1560 KB Output is correct
48 Correct 0 ms 348 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 344 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 1408 KB Output is correct
57 Correct 7 ms 1428 KB Output is correct
58 Correct 9 ms 1564 KB Output is correct
59 Correct 4 ms 920 KB Output is correct
60 Correct 4 ms 916 KB Output is correct
61 Correct 7 ms 920 KB Output is correct
62 Correct 4 ms 920 KB Output is correct
63 Correct 6 ms 884 KB Output is correct
64 Correct 5 ms 920 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 348 KB Output is correct
11 Correct 0 ms 392 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 0 ms 348 KB Output is correct
16 Correct 157 ms 18684 KB Output is correct
17 Correct 150 ms 17148 KB Output is correct
18 Correct 160 ms 17492 KB Output is correct
19 Correct 114 ms 17400 KB Output is correct
20 Correct 119 ms 18680 KB Output is correct
21 Correct 151 ms 17660 KB Output is correct
22 Correct 146 ms 16892 KB Output is correct
23 Correct 116 ms 17900 KB Output is correct
24 Correct 157 ms 18684 KB Output is correct
25 Correct 112 ms 16964 KB Output is correct
26 Correct 148 ms 17824 KB Output is correct
27 Correct 110 ms 17904 KB Output is correct
28 Correct 153 ms 18676 KB Output is correct
29 Correct 187 ms 17268 KB Output is correct
30 Correct 122 ms 17144 KB Output is correct
31 Correct 149 ms 18584 KB Output is correct
32 Correct 110 ms 17400 KB Output is correct
33 Correct 133 ms 17908 KB Output is correct
34 Correct 107 ms 17912 KB Output is correct
35 Correct 155 ms 17320 KB Output is correct
36 Correct 1 ms 344 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 6 ms 1432 KB Output is correct
41 Correct 6 ms 1564 KB Output is correct
42 Correct 6 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 5 ms 920 KB Output is correct
50 Correct 4 ms 920 KB Output is correct
51 Correct 5 ms 920 KB Output is correct
52 Correct 6 ms 920 KB Output is correct
53 Correct 5 ms 920 KB Output is correct
54 Correct 4 ms 920 KB Output is correct
55 Correct 6 ms 1076 KB Output is correct
56 Correct 4 ms 920 KB Output is correct
57 Correct 3 ms 920 KB Output is correct
58 Correct 3 ms 920 KB Output is correct
59 Correct 4 ms 916 KB Output is correct
60 Correct 4 ms 920 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 113 ms 17460 KB Output is correct
63 Correct 138 ms 17156 KB Output is correct
64 Correct 144 ms 17924 KB Output is correct
65 Correct 135 ms 17148 KB Output is correct
66 Correct 138 ms 17132 KB Output is correct
67 Correct 140 ms 17928 KB Output is correct
68 Correct 0 ms 344 KB Output is correct
69 Correct 1 ms 348 KB Output is correct
70 Correct 0 ms 344 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 114 ms 16848 KB Output is correct
75 Correct 117 ms 17156 KB Output is correct
76 Correct 117 ms 17400 KB Output is correct
77 Correct 117 ms 18224 KB Output is correct
78 Correct 136 ms 18696 KB Output is correct
79 Correct 142 ms 17152 KB Output is correct
80 Correct 131 ms 18180 KB Output is correct
81 Correct 110 ms 17920 KB Output is correct
82 Correct 107 ms 17660 KB Output is correct
83 Correct 107 ms 17404 KB Output is correct
84 Correct 118 ms 17148 KB Output is correct
85 Correct 104 ms 17144 KB Output is correct
86 Correct 111 ms 17148 KB Output is correct
87 Correct 106 ms 17412 KB Output is correct
88 Correct 0 ms 344 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 348 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 4 ms 920 KB Output is correct
105 Correct 7 ms 1560 KB Output is correct
106 Correct 7 ms 1428 KB Output is correct
107 Correct 7 ms 1436 KB Output is correct
108 Correct 7 ms 1432 KB Output is correct
109 Correct 7 ms 1560 KB Output is correct
110 Correct 0 ms 348 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 344 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 1408 KB Output is correct
119 Correct 7 ms 1428 KB Output is correct
120 Correct 9 ms 1564 KB Output is correct
121 Correct 4 ms 920 KB Output is correct
122 Correct 4 ms 916 KB Output is correct
123 Correct 7 ms 920 KB Output is correct
124 Correct 4 ms 920 KB Output is correct
125 Correct 6 ms 884 KB Output is correct
126 Correct 5 ms 920 KB Output is correct
127 Correct 5 ms 920 KB Output is correct
128 Correct 0 ms 344 KB Output is correct
129 Correct 163 ms 18016 KB Output is correct
130 Correct 248 ms 34288 KB Output is correct
131 Correct 272 ms 35104 KB Output is correct
132 Correct 258 ms 33004 KB Output is correct
133 Correct 241 ms 34288 KB Output is correct
134 Correct 260 ms 33336 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 600 KB Output is correct
140 Correct 0 ms 412 KB Output is correct
141 Correct 265 ms 33132 KB Output is correct
142 Correct 263 ms 34316 KB Output is correct
143 Correct 251 ms 34628 KB Output is correct
144 Correct 272 ms 34284 KB Output is correct
145 Correct 260 ms 34800 KB Output is correct
146 Correct 232 ms 33452 KB Output is correct
147 Correct 257 ms 34688 KB Output is correct
148 Correct 241 ms 33004 KB Output is correct
149 Correct 163 ms 18160 KB Output is correct
150 Correct 113 ms 17660 KB Output is correct
151 Correct 115 ms 17652 KB Output is correct
152 Correct 159 ms 17904 KB Output is correct
153 Correct 139 ms 18160 KB Output is correct
154 Correct 123 ms 18676 KB Output is correct
155 Correct 166 ms 18676 KB Output is correct