답안 #1105742

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1105742 2024-10-27T14:45:25 Z tuannm Fuel Station (NOI20_fuelstation) C++17
100 / 100
282 ms 20928 KB
#include<bits/stdc++.h>
#define ii pair<int, int>
#define ll pair<long long, long long>
#define fi first
#define se second
#define pb push_back
using namespace std;
const int mod[2] = {1000000007, 998244353};
const int N = 3e5 + 2;
const string NAME = "ffuel";
int n, D;
vector<int> vct;

struct SegTree{
    int n, h;
    vector<long long> tree, lazy;

    SegTree(int _n) : n(_n){
        tree.resize(2 * n, 0);
        lazy.resize(n, 0);
        h = sizeof(int) * 8 - __builtin_clz(n);
    }

    void build(){
        for(int i = 0; i < 2 * n; ++i)
            tree[i] = 0;

        for(int i = 0; i < n; ++i)
            lazy[i] = 0;
    }

    void up(int u){
        while(u > 1)
            u >>= 1, tree[u] = max(tree[u << 1], tree[u << 1 | 1]) + lazy[u];
    }

    void apply(int u, long long val){
        tree[u] += val;
        if(u < n)
            lazy[u] += val;
    }

    void down(int u){
        for(int s = h; s; --s){
            int i = u >> s;

            if(lazy[i]){
              apply(i << 1, lazy[i]);
              apply(i << 1 | 1, lazy[i]);
              lazy[i] = 0;
            }
        }
    }

    void update(int l, int r, long long val){
        l += n, r += n;
        int l0 = l, r0 = r;

        for(; l < r; l >>= 1, r >>= 1){
            if(l & 1)
                apply(l++, val);
            if(r & 1)
                apply(--r, val);
        }

        up(l0);
        up(r0 - 1);
    }

    long long query(int l, int r){
        l += n, r += n;
        down(l);
        down(r - 1);

        long long res = -2e16;

        for(; l < r; l >>= 1, r >>= 1){
            if(l & 1)
                res = max(res, tree[l++]);
            if(r & 1)
                res = max(tree[--r], res);
        }
        return res;
    }
};

struct pnt{
    int x, a, b;

    bool operator < (const pnt &other) const{
        if(b != other.b)
            return b > other.b;
        return x > other.x;
    }
} a[N];

void inp(){
    cin >> n >> D;
    vct.pb(D);

    for(int i = 1; i <= n; ++i)
        cin >> a[i].x >> a[i].a >> a[i].b, vct.pb(a[i].x);
}

void solve(){
    sort(a + 1, a + n + 1);

    sort(vct.begin(), vct.end());
    vct.resize(unique(vct.begin(), vct.end()) - vct.begin());

    int m = vct.size();
    SegTree IT(m);

    for(int i = 0; i < m; ++i)
        IT.update(i, i + 1, vct[i]);

    for(int i = 1; i <= n; ++i)
        a[i].x = lower_bound(vct.begin(), vct.end(), a[i].x) - vct.begin();

    long long ans = D;

    for(int i = 1; i <= n; ++i){
        IT.update(a[i].x + 1, m, -a[i].a);
        long long val = max(0LL, IT.query(0, m));

        if(val <= a[i].b)
            ans = min(ans, val);
    }

    cout << ans;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    if(fopen((NAME + ".inp").c_str(), "r")){
        freopen((NAME + ".inp").c_str(), "r", stdin);
        freopen((NAME + ".out").c_str(), "w", stdout);
    }

    inp();
    solve();
}

Compilation message

FuelStation.cpp: In function 'int main()':
FuelStation.cpp:139:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  139 |         freopen((NAME + ".inp").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FuelStation.cpp:140:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  140 |         freopen((NAME + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 135 ms 6596 KB Output is correct
2 Correct 152 ms 6596 KB Output is correct
3 Correct 156 ms 8388 KB Output is correct
4 Correct 116 ms 6596 KB Output is correct
5 Correct 124 ms 9156 KB Output is correct
6 Correct 143 ms 6608 KB Output is correct
7 Correct 144 ms 9896 KB Output is correct
8 Correct 116 ms 6596 KB Output is correct
9 Correct 145 ms 6620 KB Output is correct
10 Correct 120 ms 6596 KB Output is correct
11 Correct 147 ms 8644 KB Output is correct
12 Correct 139 ms 6592 KB Output is correct
13 Correct 140 ms 6608 KB Output is correct
14 Correct 141 ms 8896 KB Output is correct
15 Correct 117 ms 6600 KB Output is correct
16 Correct 156 ms 6600 KB Output is correct
17 Correct 122 ms 6596 KB Output is correct
18 Correct 141 ms 6636 KB Output is correct
19 Correct 118 ms 6596 KB Output is correct
20 Correct 145 ms 6596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 5 ms 592 KB Output is correct
3 Correct 7 ms 848 KB Output is correct
4 Correct 7 ms 848 KB Output is correct
5 Correct 7 ms 848 KB Output is correct
6 Correct 7 ms 848 KB Output is correct
7 Correct 7 ms 848 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 5 ms 848 KB Output is correct
15 Correct 5 ms 592 KB Output is correct
16 Correct 5 ms 620 KB Output is correct
17 Correct 7 ms 848 KB Output is correct
18 Correct 6 ms 692 KB Output is correct
19 Correct 5 ms 592 KB Output is correct
20 Correct 5 ms 848 KB Output is correct
21 Correct 5 ms 592 KB Output is correct
22 Correct 4 ms 592 KB Output is correct
23 Correct 5 ms 832 KB Output is correct
24 Correct 5 ms 760 KB Output is correct
25 Correct 6 ms 792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 5 ms 592 KB Output is correct
3 Correct 7 ms 848 KB Output is correct
4 Correct 7 ms 848 KB Output is correct
5 Correct 7 ms 848 KB Output is correct
6 Correct 7 ms 848 KB Output is correct
7 Correct 7 ms 848 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 5 ms 848 KB Output is correct
15 Correct 5 ms 592 KB Output is correct
16 Correct 5 ms 620 KB Output is correct
17 Correct 7 ms 848 KB Output is correct
18 Correct 6 ms 692 KB Output is correct
19 Correct 5 ms 592 KB Output is correct
20 Correct 5 ms 848 KB Output is correct
21 Correct 5 ms 592 KB Output is correct
22 Correct 4 ms 592 KB Output is correct
23 Correct 5 ms 832 KB Output is correct
24 Correct 5 ms 760 KB Output is correct
25 Correct 6 ms 792 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 122 ms 8908 KB Output is correct
28 Correct 153 ms 8988 KB Output is correct
29 Correct 148 ms 9684 KB Output is correct
30 Correct 149 ms 8644 KB Output is correct
31 Correct 156 ms 6596 KB Output is correct
32 Correct 148 ms 6596 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 336 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 122 ms 6700 KB Output is correct
40 Correct 132 ms 10180 KB Output is correct
41 Correct 131 ms 8900 KB Output is correct
42 Correct 131 ms 6516 KB Output is correct
43 Correct 146 ms 8900 KB Output is correct
44 Correct 131 ms 6596 KB Output is correct
45 Correct 119 ms 6604 KB Output is correct
46 Correct 119 ms 6620 KB Output is correct
47 Correct 103 ms 11204 KB Output is correct
48 Correct 109 ms 6596 KB Output is correct
49 Correct 128 ms 8616 KB Output is correct
50 Correct 128 ms 9924 KB Output is correct
51 Correct 123 ms 8884 KB Output is correct
52 Correct 121 ms 8732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 508 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 504 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 5 ms 592 KB Output is correct
18 Correct 7 ms 848 KB Output is correct
19 Correct 7 ms 848 KB Output is correct
20 Correct 7 ms 848 KB Output is correct
21 Correct 7 ms 848 KB Output is correct
22 Correct 7 ms 848 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 5 ms 848 KB Output is correct
30 Correct 5 ms 592 KB Output is correct
31 Correct 5 ms 620 KB Output is correct
32 Correct 7 ms 848 KB Output is correct
33 Correct 6 ms 692 KB Output is correct
34 Correct 5 ms 592 KB Output is correct
35 Correct 5 ms 848 KB Output is correct
36 Correct 5 ms 592 KB Output is correct
37 Correct 4 ms 592 KB Output is correct
38 Correct 5 ms 832 KB Output is correct
39 Correct 5 ms 760 KB Output is correct
40 Correct 6 ms 792 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 5 ms 848 KB Output is correct
43 Correct 8 ms 1104 KB Output is correct
44 Correct 8 ms 1128 KB Output is correct
45 Correct 9 ms 860 KB Output is correct
46 Correct 8 ms 1272 KB Output is correct
47 Correct 8 ms 1104 KB Output is correct
48 Correct 1 ms 336 KB Output is correct
49 Correct 1 ms 468 KB Output is correct
50 Correct 1 ms 336 KB Output is correct
51 Correct 1 ms 336 KB Output is correct
52 Correct 1 ms 336 KB Output is correct
53 Correct 1 ms 336 KB Output is correct
54 Correct 7 ms 848 KB Output is correct
55 Correct 8 ms 1104 KB Output is correct
56 Correct 8 ms 1104 KB Output is correct
57 Correct 7 ms 848 KB Output is correct
58 Correct 8 ms 1104 KB Output is correct
59 Correct 5 ms 848 KB Output is correct
60 Correct 5 ms 592 KB Output is correct
61 Correct 5 ms 592 KB Output is correct
62 Correct 5 ms 940 KB Output is correct
63 Correct 5 ms 688 KB Output is correct
64 Correct 6 ms 592 KB Output is correct
65 Correct 6 ms 836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 135 ms 6596 KB Output is correct
17 Correct 152 ms 6596 KB Output is correct
18 Correct 156 ms 8388 KB Output is correct
19 Correct 116 ms 6596 KB Output is correct
20 Correct 124 ms 9156 KB Output is correct
21 Correct 143 ms 6608 KB Output is correct
22 Correct 144 ms 9896 KB Output is correct
23 Correct 116 ms 6596 KB Output is correct
24 Correct 145 ms 6620 KB Output is correct
25 Correct 120 ms 6596 KB Output is correct
26 Correct 147 ms 8644 KB Output is correct
27 Correct 139 ms 6592 KB Output is correct
28 Correct 140 ms 6608 KB Output is correct
29 Correct 141 ms 8896 KB Output is correct
30 Correct 117 ms 6600 KB Output is correct
31 Correct 156 ms 6600 KB Output is correct
32 Correct 122 ms 6596 KB Output is correct
33 Correct 141 ms 6636 KB Output is correct
34 Correct 118 ms 6596 KB Output is correct
35 Correct 145 ms 6596 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 5 ms 592 KB Output is correct
38 Correct 7 ms 848 KB Output is correct
39 Correct 7 ms 848 KB Output is correct
40 Correct 7 ms 848 KB Output is correct
41 Correct 7 ms 848 KB Output is correct
42 Correct 7 ms 848 KB Output is correct
43 Correct 1 ms 336 KB Output is correct
44 Correct 1 ms 336 KB Output is correct
45 Correct 1 ms 336 KB Output is correct
46 Correct 1 ms 336 KB Output is correct
47 Correct 1 ms 336 KB Output is correct
48 Correct 1 ms 336 KB Output is correct
49 Correct 5 ms 848 KB Output is correct
50 Correct 5 ms 592 KB Output is correct
51 Correct 5 ms 620 KB Output is correct
52 Correct 7 ms 848 KB Output is correct
53 Correct 6 ms 692 KB Output is correct
54 Correct 5 ms 592 KB Output is correct
55 Correct 5 ms 848 KB Output is correct
56 Correct 5 ms 592 KB Output is correct
57 Correct 4 ms 592 KB Output is correct
58 Correct 5 ms 832 KB Output is correct
59 Correct 5 ms 760 KB Output is correct
60 Correct 6 ms 792 KB Output is correct
61 Correct 1 ms 336 KB Output is correct
62 Correct 122 ms 8908 KB Output is correct
63 Correct 153 ms 8988 KB Output is correct
64 Correct 148 ms 9684 KB Output is correct
65 Correct 149 ms 8644 KB Output is correct
66 Correct 156 ms 6596 KB Output is correct
67 Correct 148 ms 6596 KB Output is correct
68 Correct 1 ms 336 KB Output is correct
69 Correct 1 ms 336 KB Output is correct
70 Correct 1 ms 336 KB Output is correct
71 Correct 1 ms 336 KB Output is correct
72 Correct 1 ms 336 KB Output is correct
73 Correct 1 ms 336 KB Output is correct
74 Correct 122 ms 6700 KB Output is correct
75 Correct 132 ms 10180 KB Output is correct
76 Correct 131 ms 8900 KB Output is correct
77 Correct 131 ms 6516 KB Output is correct
78 Correct 146 ms 8900 KB Output is correct
79 Correct 131 ms 6596 KB Output is correct
80 Correct 119 ms 6604 KB Output is correct
81 Correct 119 ms 6620 KB Output is correct
82 Correct 103 ms 11204 KB Output is correct
83 Correct 109 ms 6596 KB Output is correct
84 Correct 128 ms 8616 KB Output is correct
85 Correct 128 ms 9924 KB Output is correct
86 Correct 123 ms 8884 KB Output is correct
87 Correct 121 ms 8732 KB Output is correct
88 Correct 1 ms 336 KB Output is correct
89 Correct 1 ms 336 KB Output is correct
90 Correct 1 ms 336 KB Output is correct
91 Correct 1 ms 336 KB Output is correct
92 Correct 1 ms 336 KB Output is correct
93 Correct 1 ms 336 KB Output is correct
94 Correct 1 ms 336 KB Output is correct
95 Correct 1 ms 336 KB Output is correct
96 Correct 1 ms 336 KB Output is correct
97 Correct 1 ms 336 KB Output is correct
98 Correct 1 ms 336 KB Output is correct
99 Correct 1 ms 508 KB Output is correct
100 Correct 1 ms 336 KB Output is correct
101 Correct 1 ms 504 KB Output is correct
102 Correct 1 ms 336 KB Output is correct
103 Correct 1 ms 336 KB Output is correct
104 Correct 5 ms 848 KB Output is correct
105 Correct 8 ms 1104 KB Output is correct
106 Correct 8 ms 1128 KB Output is correct
107 Correct 9 ms 860 KB Output is correct
108 Correct 8 ms 1272 KB Output is correct
109 Correct 8 ms 1104 KB Output is correct
110 Correct 1 ms 336 KB Output is correct
111 Correct 1 ms 468 KB Output is correct
112 Correct 1 ms 336 KB Output is correct
113 Correct 1 ms 336 KB Output is correct
114 Correct 1 ms 336 KB Output is correct
115 Correct 1 ms 336 KB Output is correct
116 Correct 7 ms 848 KB Output is correct
117 Correct 8 ms 1104 KB Output is correct
118 Correct 8 ms 1104 KB Output is correct
119 Correct 7 ms 848 KB Output is correct
120 Correct 8 ms 1104 KB Output is correct
121 Correct 5 ms 848 KB Output is correct
122 Correct 5 ms 592 KB Output is correct
123 Correct 5 ms 592 KB Output is correct
124 Correct 5 ms 940 KB Output is correct
125 Correct 5 ms 688 KB Output is correct
126 Correct 6 ms 592 KB Output is correct
127 Correct 6 ms 836 KB Output is correct
128 Correct 1 ms 336 KB Output is correct
129 Correct 179 ms 6688 KB Output is correct
130 Correct 282 ms 17428 KB Output is correct
131 Correct 274 ms 13008 KB Output is correct
132 Correct 262 ms 17344 KB Output is correct
133 Correct 266 ms 13012 KB Output is correct
134 Correct 266 ms 13152 KB Output is correct
135 Correct 1 ms 336 KB Output is correct
136 Correct 1 ms 336 KB Output is correct
137 Correct 1 ms 336 KB Output is correct
138 Correct 1 ms 336 KB Output is correct
139 Correct 1 ms 336 KB Output is correct
140 Correct 1 ms 504 KB Output is correct
141 Correct 253 ms 20476 KB Output is correct
142 Correct 237 ms 12988 KB Output is correct
143 Correct 240 ms 12992 KB Output is correct
144 Correct 244 ms 20928 KB Output is correct
145 Correct 238 ms 12992 KB Output is correct
146 Correct 230 ms 16576 KB Output is correct
147 Correct 228 ms 20068 KB Output is correct
148 Correct 229 ms 12920 KB Output is correct
149 Correct 189 ms 12996 KB Output is correct
150 Correct 121 ms 6596 KB Output is correct
151 Correct 122 ms 6596 KB Output is correct
152 Correct 176 ms 6596 KB Output is correct
153 Correct 155 ms 6596 KB Output is correct
154 Correct 137 ms 13000 KB Output is correct
155 Correct 185 ms 13156 KB Output is correct