답안 #1002244

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




# 결과 실행 시간 메모리 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 1 ms 464 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 468 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 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 152 ms 16888 KB Output is correct
2 Correct 144 ms 17348 KB Output is correct
3 Correct 151 ms 18000 KB Output is correct
4 Correct 111 ms 17892 KB Output is correct
5 Correct 119 ms 17908 KB Output is correct
6 Correct 155 ms 18420 KB Output is correct
7 Correct 143 ms 17084 KB Output is correct
8 Correct 106 ms 18688 KB Output is correct
9 Correct 142 ms 17664 KB Output is correct
10 Correct 106 ms 18352 KB Output is correct
11 Correct 141 ms 17772 KB Output is correct
12 Correct 106 ms 18260 KB Output is correct
13 Correct 137 ms 18420 KB Output is correct
14 Correct 136 ms 17660 KB Output is correct
15 Correct 106 ms 17892 KB Output is correct
16 Correct 166 ms 18164 KB Output is correct
17 Correct 118 ms 17800 KB Output is correct
18 Correct 136 ms 17148 KB Output is correct
19 Correct 109 ms 17404 KB Output is correct
20 Correct 145 ms 17656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 4 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 7 ms 1432 KB Output is correct
6 Correct 6 ms 1432 KB Output is correct
7 Correct 6 ms 1432 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 344 KB Output is correct
14 Correct 4 ms 920 KB Output is correct
15 Correct 4 ms 920 KB Output is correct
16 Correct 5 ms 956 KB Output is correct
17 Correct 5 ms 920 KB Output is correct
18 Correct 5 ms 920 KB Output is correct
19 Correct 4 ms 916 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 3 ms 1168 KB Output is correct
24 Correct 4 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 4 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 7 ms 1432 KB Output is correct
6 Correct 6 ms 1432 KB Output is correct
7 Correct 6 ms 1432 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 344 KB Output is correct
14 Correct 4 ms 920 KB Output is correct
15 Correct 4 ms 920 KB Output is correct
16 Correct 5 ms 956 KB Output is correct
17 Correct 5 ms 920 KB Output is correct
18 Correct 5 ms 920 KB Output is correct
19 Correct 4 ms 916 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 3 ms 1168 KB Output is correct
24 Correct 4 ms 920 KB Output is correct
25 Correct 4 ms 920 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 110 ms 16920 KB Output is correct
28 Correct 134 ms 18436 KB Output is correct
29 Correct 139 ms 18380 KB Output is correct
30 Correct 134 ms 16892 KB Output is correct
31 Correct 139 ms 17920 KB Output is correct
32 Correct 144 ms 18424 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 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 130 ms 21512 KB Output is correct
40 Correct 122 ms 22556 KB Output is correct
41 Correct 118 ms 20864 KB Output is correct
42 Correct 113 ms 21244 KB Output is correct
43 Correct 163 ms 22024 KB Output is correct
44 Correct 127 ms 20992 KB Output is correct
45 Correct 124 ms 20480 KB Output is correct
46 Correct 128 ms 22424 KB Output is correct
47 Correct 106 ms 23116 KB Output is correct
48 Correct 108 ms 22592 KB Output is correct
49 Correct 122 ms 20828 KB Output is correct
50 Correct 110 ms 21244 KB Output is correct
51 Correct 114 ms 22268 KB Output is correct
52 Correct 106 ms 22268 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 348 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 468 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 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 436 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 344 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 1 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 348 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 468 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 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 436 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 4 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 7 ms 1432 KB Output is correct
21 Correct 6 ms 1432 KB Output is correct
22 Correct 6 ms 1432 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 344 KB Output is correct
29 Correct 4 ms 920 KB Output is correct
30 Correct 4 ms 920 KB Output is correct
31 Correct 5 ms 956 KB Output is correct
32 Correct 5 ms 920 KB Output is correct
33 Correct 5 ms 920 KB Output is correct
34 Correct 4 ms 916 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 3 ms 1168 KB Output is correct
39 Correct 4 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 4 ms 1252 KB Output is correct
43 Correct 7 ms 1688 KB Output is correct
44 Correct 7 ms 1688 KB Output is correct
45 Correct 8 ms 1688 KB Output is correct
46 Correct 7 ms 1688 KB Output is correct
47 Correct 7 ms 1708 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 1 ms 348 KB Output is correct
54 Correct 7 ms 1688 KB Output is correct
55 Correct 7 ms 1824 KB Output is correct
56 Correct 7 ms 1688 KB Output is correct
57 Correct 7 ms 1704 KB Output is correct
58 Correct 7 ms 1688 KB Output is correct
59 Correct 4 ms 1176 KB Output is correct
60 Correct 5 ms 1176 KB Output is correct
61 Correct 5 ms 1176 KB Output is correct
62 Correct 5 ms 1248 KB Output is correct
63 Correct 5 ms 1176 KB Output is correct
64 Correct 5 ms 1176 KB Output is correct
65 Correct 5 ms 1116 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 348 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 468 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 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 436 KB Output is correct
16 Correct 152 ms 16888 KB Output is correct
17 Correct 144 ms 17348 KB Output is correct
18 Correct 151 ms 18000 KB Output is correct
19 Correct 111 ms 17892 KB Output is correct
20 Correct 119 ms 17908 KB Output is correct
21 Correct 155 ms 18420 KB Output is correct
22 Correct 143 ms 17084 KB Output is correct
23 Correct 106 ms 18688 KB Output is correct
24 Correct 142 ms 17664 KB Output is correct
25 Correct 106 ms 18352 KB Output is correct
26 Correct 141 ms 17772 KB Output is correct
27 Correct 106 ms 18260 KB Output is correct
28 Correct 137 ms 18420 KB Output is correct
29 Correct 136 ms 17660 KB Output is correct
30 Correct 106 ms 17892 KB Output is correct
31 Correct 166 ms 18164 KB Output is correct
32 Correct 118 ms 17800 KB Output is correct
33 Correct 136 ms 17148 KB Output is correct
34 Correct 109 ms 17404 KB Output is correct
35 Correct 145 ms 17656 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 4 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 7 ms 1432 KB Output is correct
41 Correct 6 ms 1432 KB Output is correct
42 Correct 6 ms 1432 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 344 KB Output is correct
49 Correct 4 ms 920 KB Output is correct
50 Correct 4 ms 920 KB Output is correct
51 Correct 5 ms 956 KB Output is correct
52 Correct 5 ms 920 KB Output is correct
53 Correct 5 ms 920 KB Output is correct
54 Correct 4 ms 916 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 3 ms 1168 KB Output is correct
59 Correct 4 ms 920 KB Output is correct
60 Correct 4 ms 920 KB Output is correct
61 Correct 1 ms 344 KB Output is correct
62 Correct 110 ms 16920 KB Output is correct
63 Correct 134 ms 18436 KB Output is correct
64 Correct 139 ms 18380 KB Output is correct
65 Correct 134 ms 16892 KB Output is correct
66 Correct 139 ms 17920 KB Output is correct
67 Correct 144 ms 18424 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 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 130 ms 21512 KB Output is correct
75 Correct 122 ms 22556 KB Output is correct
76 Correct 118 ms 20864 KB Output is correct
77 Correct 113 ms 21244 KB Output is correct
78 Correct 163 ms 22024 KB Output is correct
79 Correct 127 ms 20992 KB Output is correct
80 Correct 124 ms 20480 KB Output is correct
81 Correct 128 ms 22424 KB Output is correct
82 Correct 106 ms 23116 KB Output is correct
83 Correct 108 ms 22592 KB Output is correct
84 Correct 122 ms 20828 KB Output is correct
85 Correct 110 ms 21244 KB Output is correct
86 Correct 114 ms 22268 KB Output is correct
87 Correct 106 ms 22268 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 344 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 1 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 1252 KB Output is correct
105 Correct 7 ms 1688 KB Output is correct
106 Correct 7 ms 1688 KB Output is correct
107 Correct 8 ms 1688 KB Output is correct
108 Correct 7 ms 1688 KB Output is correct
109 Correct 7 ms 1708 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 1 ms 348 KB Output is correct
116 Correct 7 ms 1688 KB Output is correct
117 Correct 7 ms 1824 KB Output is correct
118 Correct 7 ms 1688 KB Output is correct
119 Correct 7 ms 1704 KB Output is correct
120 Correct 7 ms 1688 KB Output is correct
121 Correct 4 ms 1176 KB Output is correct
122 Correct 5 ms 1176 KB Output is correct
123 Correct 5 ms 1176 KB Output is correct
124 Correct 5 ms 1248 KB Output is correct
125 Correct 5 ms 1176 KB Output is correct
126 Correct 5 ms 1176 KB Output is correct
127 Correct 5 ms 1116 KB Output is correct
128 Correct 0 ms 348 KB Output is correct
129 Correct 164 ms 24660 KB Output is correct
130 Correct 260 ms 42996 KB Output is correct
131 Correct 270 ms 43756 KB Output is correct
132 Correct 275 ms 43368 KB Output is correct
133 Correct 270 ms 43248 KB Output is correct
134 Correct 254 ms 43424 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 472 KB Output is correct
140 Correct 0 ms 348 KB Output is correct
141 Correct 274 ms 42620 KB Output is correct
142 Correct 279 ms 43024 KB Output is correct
143 Correct 261 ms 41968 KB Output is correct
144 Correct 267 ms 44984 KB Output is correct
145 Correct 264 ms 43420 KB Output is correct
146 Correct 258 ms 41204 KB Output is correct
147 Correct 244 ms 42372 KB Output is correct
148 Correct 246 ms 40272 KB Output is correct
149 Correct 165 ms 25808 KB Output is correct
150 Correct 118 ms 26288 KB Output is correct
151 Correct 117 ms 26104 KB Output is correct
152 Correct 164 ms 24820 KB Output is correct
153 Correct 124 ms 24964 KB Output is correct
154 Correct 123 ms 24316 KB Output is correct
155 Correct 156 ms 24508 KB Output is correct