답안 #1002249

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1002249 2024-06-19T11:29:13 Z vjudge1 Fuel Station (NOI20_fuelstation) C++17
100 / 100
286 ms 35508 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 satisfied  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();
}




# 결과 실행 시간 메모리 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 412 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 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 155 ms 17656 KB Output is correct
2 Correct 159 ms 17400 KB Output is correct
3 Correct 150 ms 18492 KB Output is correct
4 Correct 113 ms 17656 KB Output is correct
5 Correct 116 ms 17240 KB Output is correct
6 Correct 153 ms 18680 KB Output is correct
7 Correct 147 ms 18044 KB Output is correct
8 Correct 115 ms 17104 KB Output is correct
9 Correct 161 ms 17656 KB Output is correct
10 Correct 112 ms 17516 KB Output is correct
11 Correct 149 ms 17144 KB Output is correct
12 Correct 117 ms 16896 KB Output is correct
13 Correct 153 ms 17316 KB Output is correct
14 Correct 142 ms 17652 KB Output is correct
15 Correct 116 ms 17152 KB Output is correct
16 Correct 156 ms 18176 KB Output is correct
17 Correct 124 ms 18164 KB Output is correct
18 Correct 151 ms 17396 KB Output is correct
19 Correct 115 ms 16892 KB Output is correct
20 Correct 146 ms 17904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 3 ms 920 KB Output is correct
3 Correct 7 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 6 ms 1560 KB Output is correct
7 Correct 6 ms 1444 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 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 6 ms 920 KB Output is correct
15 Correct 5 ms 916 KB Output is correct
16 Correct 5 ms 920 KB Output is correct
17 Correct 5 ms 920 KB Output is correct
18 Correct 5 ms 920 KB Output is correct
19 Correct 3 ms 884 KB Output is correct
20 Correct 4 ms 1024 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 3 ms 920 KB Output is correct
25 Correct 4 ms 920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 3 ms 920 KB Output is correct
3 Correct 7 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 6 ms 1560 KB Output is correct
7 Correct 6 ms 1444 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 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 6 ms 920 KB Output is correct
15 Correct 5 ms 916 KB Output is correct
16 Correct 5 ms 920 KB Output is correct
17 Correct 5 ms 920 KB Output is correct
18 Correct 5 ms 920 KB Output is correct
19 Correct 3 ms 884 KB Output is correct
20 Correct 4 ms 1024 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 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 108 ms 18740 KB Output is correct
28 Correct 139 ms 16884 KB Output is correct
29 Correct 139 ms 17916 KB Output is correct
30 Correct 138 ms 18164 KB Output is correct
31 Correct 144 ms 16888 KB Output is correct
32 Correct 148 ms 17400 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 408 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 112 ms 18496 KB Output is correct
40 Correct 116 ms 18684 KB Output is correct
41 Correct 121 ms 16904 KB Output is correct
42 Correct 110 ms 16892 KB Output is correct
43 Correct 136 ms 17148 KB Output is correct
44 Correct 123 ms 18692 KB Output is correct
45 Correct 122 ms 17624 KB Output is correct
46 Correct 110 ms 18552 KB Output is correct
47 Correct 110 ms 18148 KB Output is correct
48 Correct 98 ms 16892 KB Output is correct
49 Correct 123 ms 17544 KB Output is correct
50 Correct 106 ms 18600 KB Output is correct
51 Correct 111 ms 18168 KB Output is correct
52 Correct 104 ms 17908 KB Output is correct
# 결과 실행 시간 메모리 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 412 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 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 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 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
# 결과 실행 시간 메모리 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 412 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 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 3 ms 920 KB Output is correct
18 Correct 7 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 6 ms 1560 KB Output is correct
22 Correct 6 ms 1444 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 344 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 6 ms 920 KB Output is correct
30 Correct 5 ms 916 KB Output is correct
31 Correct 5 ms 920 KB Output is correct
32 Correct 5 ms 920 KB Output is correct
33 Correct 5 ms 920 KB Output is correct
34 Correct 3 ms 884 KB Output is correct
35 Correct 4 ms 1024 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 3 ms 920 KB Output is correct
40 Correct 4 ms 920 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 4 ms 920 KB Output is correct
43 Correct 7 ms 1388 KB Output is correct
44 Correct 7 ms 1428 KB Output is correct
45 Correct 7 ms 1432 KB Output is correct
46 Correct 7 ms 1432 KB Output is correct
47 Correct 7 ms 1432 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 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 9 ms 1432 KB Output is correct
55 Correct 7 ms 1428 KB Output is correct
56 Correct 7 ms 1432 KB Output is correct
57 Correct 7 ms 1432 KB Output is correct
58 Correct 7 ms 1440 KB Output is correct
59 Correct 4 ms 920 KB Output is correct
60 Correct 5 ms 884 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 6 ms 920 KB Output is correct
65 Correct 6 ms 920 KB Output is correct
# 결과 실행 시간 메모리 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 412 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 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 155 ms 17656 KB Output is correct
17 Correct 159 ms 17400 KB Output is correct
18 Correct 150 ms 18492 KB Output is correct
19 Correct 113 ms 17656 KB Output is correct
20 Correct 116 ms 17240 KB Output is correct
21 Correct 153 ms 18680 KB Output is correct
22 Correct 147 ms 18044 KB Output is correct
23 Correct 115 ms 17104 KB Output is correct
24 Correct 161 ms 17656 KB Output is correct
25 Correct 112 ms 17516 KB Output is correct
26 Correct 149 ms 17144 KB Output is correct
27 Correct 117 ms 16896 KB Output is correct
28 Correct 153 ms 17316 KB Output is correct
29 Correct 142 ms 17652 KB Output is correct
30 Correct 116 ms 17152 KB Output is correct
31 Correct 156 ms 18176 KB Output is correct
32 Correct 124 ms 18164 KB Output is correct
33 Correct 151 ms 17396 KB Output is correct
34 Correct 115 ms 16892 KB Output is correct
35 Correct 146 ms 17904 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 3 ms 920 KB Output is correct
38 Correct 7 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 6 ms 1560 KB Output is correct
42 Correct 6 ms 1444 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 344 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 6 ms 920 KB Output is correct
50 Correct 5 ms 916 KB Output is correct
51 Correct 5 ms 920 KB Output is correct
52 Correct 5 ms 920 KB Output is correct
53 Correct 5 ms 920 KB Output is correct
54 Correct 3 ms 884 KB Output is correct
55 Correct 4 ms 1024 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 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 108 ms 18740 KB Output is correct
63 Correct 139 ms 16884 KB Output is correct
64 Correct 139 ms 17916 KB Output is correct
65 Correct 138 ms 18164 KB Output is correct
66 Correct 144 ms 16888 KB Output is correct
67 Correct 148 ms 17400 KB Output is correct
68 Correct 0 ms 348 KB Output is correct
69 Correct 0 ms 348 KB Output is correct
70 Correct 0 ms 408 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 112 ms 18496 KB Output is correct
75 Correct 116 ms 18684 KB Output is correct
76 Correct 121 ms 16904 KB Output is correct
77 Correct 110 ms 16892 KB Output is correct
78 Correct 136 ms 17148 KB Output is correct
79 Correct 123 ms 18692 KB Output is correct
80 Correct 122 ms 17624 KB Output is correct
81 Correct 110 ms 18552 KB Output is correct
82 Correct 110 ms 18148 KB Output is correct
83 Correct 98 ms 16892 KB Output is correct
84 Correct 123 ms 17544 KB Output is correct
85 Correct 106 ms 18600 KB Output is correct
86 Correct 111 ms 18168 KB Output is correct
87 Correct 104 ms 17908 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 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 344 KB Output is correct
104 Correct 4 ms 920 KB Output is correct
105 Correct 7 ms 1388 KB Output is correct
106 Correct 7 ms 1428 KB Output is correct
107 Correct 7 ms 1432 KB Output is correct
108 Correct 7 ms 1432 KB Output is correct
109 Correct 7 ms 1432 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 348 KB Output is correct
114 Correct 0 ms 348 KB Output is correct
115 Correct 0 ms 348 KB Output is correct
116 Correct 9 ms 1432 KB Output is correct
117 Correct 7 ms 1428 KB Output is correct
118 Correct 7 ms 1432 KB Output is correct
119 Correct 7 ms 1432 KB Output is correct
120 Correct 7 ms 1440 KB Output is correct
121 Correct 4 ms 920 KB Output is correct
122 Correct 5 ms 884 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 6 ms 920 KB Output is correct
127 Correct 6 ms 920 KB Output is correct
128 Correct 0 ms 348 KB Output is correct
129 Correct 161 ms 17024 KB Output is correct
130 Correct 248 ms 34028 KB Output is correct
131 Correct 251 ms 33512 KB Output is correct
132 Correct 265 ms 34796 KB Output is correct
133 Correct 258 ms 34276 KB Output is correct
134 Correct 256 ms 33772 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 286 ms 34340 KB Output is correct
142 Correct 269 ms 35508 KB Output is correct
143 Correct 260 ms 34792 KB Output is correct
144 Correct 279 ms 35316 KB Output is correct
145 Correct 249 ms 34124 KB Output is correct
146 Correct 260 ms 34800 KB Output is correct
147 Correct 255 ms 33520 KB Output is correct
148 Correct 256 ms 34032 KB Output is correct
149 Correct 160 ms 17916 KB Output is correct
150 Correct 114 ms 18680 KB Output is correct
151 Correct 108 ms 18676 KB Output is correct
152 Correct 161 ms 17148 KB Output is correct
153 Correct 125 ms 17148 KB Output is correct
154 Correct 123 ms 17656 KB Output is correct
155 Correct 164 ms 18424 KB Output is correct