답안 #1105819

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1105819 2024-10-28T02:39:50 Z whoknow Fuel Station (NOI20_fuelstation) C++17
100 / 100
262 ms 46664 KB
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define F first
#define S second
#define MAXN 300005
#define ii pair<int,int>
#define bit(i,j) ((i>>j)&1)
#define sz(i) (int)i.size()
#define endl '\n'
using namespace std;
const ll INF = 1e18;
int n, D;
struct arr
{
    int x, A, B, id;
};
arr a[MAXN], b[MAXN];
namespace sub1
{
int res = -1;
ll st[4 * MAXN], lazy[4 * MAXN];
void seg(int id, int l, int r)
{
    if(l == r)
        return st[id] = a[l].x, void();
    int mid = (l + r) / 2;
    seg(id * 2, l, mid);
    seg(id * 2 + 1, mid + 1, r);
    st[id] = max(st[id * 2], st[id * 2 + 1]);
}
void down(int id)
{
    ll t = lazy[id];
    st[id * 2] += t;
    st[id * 2 + 1] += t;
    lazy[id * 2] += t;
    lazy[id * 2 + 1] += t;
    lazy[id] = 0;
}
void update(int id, int l, int r, int u, int v, int k)
{
    if(l > v || r < u)
        return ;
    if(l >= u && r <= v)
    {
        st[id] += k;
        lazy[id] += k;
        return ;
    }
    if(lazy[id]!=0)
        down(id);
    int mid = (l + r) / 2;
    update(id * 2, l, mid, u, v, k);
    update(id * 2 + 1, mid + 1, r, u, v, k);
    st[id] = max(st[id * 2], st[id * 2 + 1]);
}
ll get(int id, int l, int r, int u, int v)
{
    if(l > v || r < u)
        return -INF;
    if(l >= u && r <= v)
        return st[id];
    if(lazy[id]!=0)
        down(id);
    int mid = (l + r) / 2;
    return max(get(id * 2, l, mid, u, v), get(id * 2 + 1, mid + 1, r, u, v));
}
bool cmp1(arr x, arr y)
{
    return x.x < y.x;
}
bool cmp2(arr x, arr y)
{
    return x.B < y.B;
}
bool check(int x)
{
    ll t = x;
    for(int i = 1; i <= n; i++)
    {
        if(t < a[i].x)
            return 0;
        if(x <= a[i].B)
            t += a[i].A;
    }
    return 1;
}
int bina(int pos)
{
    int l = b[pos - 1].B + 1, r = b[pos].B;
    while(l < r)
    {
        int mid = (l + r) / 2;
        if(check(mid))
            r = mid;
        else
            l = mid + 1;
    }
    return r;
}
void solve()
{
    n++;
    a[n] = {D, 0, 0, n};
    sort(a + 1, a + 1 + n, cmp1);
    seg(1, 1, n);
    for(int i = 1; i <= n; i++)
    {
        a[i].id=i;
        b[i] = a[i];
    }
    sort(b + 1, b + 1 + n, cmp2);
    for(int i = n; i >= 1; i--)
    {
        update(1, 1, n, 1, n, b[i+1].B-b[i].B);
        update(1, 1, n, b[i].id + 1, n, -b[i].A);
        if(get(1, 1, n, 1, n) <= 0)
            res = i;
    }
    if(res == -1)
        return cout << D, void();
    cout << bina(res);
}
}
main()
{
    if(fopen("TEST.inp", "r"))
    {
        freopen("TEST.inp", "r", stdin);
        freopen("TEST.out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> D;
    for(int i = 1; i <= n; i++)
        cin >> a[i].x >> a[i].A >> a[i].B;
    sub1::solve();
}

Compilation message

FuelStation.cpp:126:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  126 | main()
      | ^~~~
FuelStation.cpp: In function 'int main()':
FuelStation.cpp:130:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  130 |         freopen("TEST.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
FuelStation.cpp:131:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  131 |         freopen("TEST.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 1 ms 6480 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 1 ms 6480 KB Output is correct
5 Correct 1 ms 6648 KB Output is correct
6 Correct 1 ms 6480 KB Output is correct
7 Correct 1 ms 6480 KB Output is correct
8 Correct 1 ms 6612 KB Output is correct
9 Correct 1 ms 6480 KB Output is correct
10 Correct 1 ms 6480 KB Output is correct
11 Correct 1 ms 6480 KB Output is correct
12 Correct 1 ms 6480 KB Output is correct
13 Correct 1 ms 6480 KB Output is correct
14 Correct 1 ms 6480 KB Output is correct
15 Correct 1 ms 6480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 182 ms 37976 KB Output is correct
2 Correct 184 ms 37964 KB Output is correct
3 Correct 208 ms 37844 KB Output is correct
4 Correct 185 ms 37960 KB Output is correct
5 Correct 172 ms 37844 KB Output is correct
6 Correct 185 ms 37960 KB Output is correct
7 Correct 193 ms 37960 KB Output is correct
8 Correct 190 ms 37844 KB Output is correct
9 Correct 196 ms 37964 KB Output is correct
10 Correct 186 ms 37960 KB Output is correct
11 Correct 180 ms 37836 KB Output is correct
12 Correct 179 ms 37960 KB Output is correct
13 Correct 197 ms 37848 KB Output is correct
14 Correct 172 ms 37848 KB Output is correct
15 Correct 188 ms 37960 KB Output is correct
16 Correct 196 ms 37840 KB Output is correct
17 Correct 182 ms 37832 KB Output is correct
18 Correct 189 ms 37960 KB Output is correct
19 Correct 175 ms 37964 KB Output is correct
20 Correct 172 ms 38100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 7 ms 8784 KB Output is correct
3 Correct 7 ms 8776 KB Output is correct
4 Correct 8 ms 8784 KB Output is correct
5 Correct 7 ms 8784 KB Output is correct
6 Correct 8 ms 8952 KB Output is correct
7 Correct 7 ms 8996 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
9 Correct 1 ms 6480 KB Output is correct
10 Correct 2 ms 6480 KB Output is correct
11 Correct 1 ms 6480 KB Output is correct
12 Correct 1 ms 6480 KB Output is correct
13 Correct 1 ms 6480 KB Output is correct
14 Correct 7 ms 8992 KB Output is correct
15 Correct 7 ms 8784 KB Output is correct
16 Correct 7 ms 8784 KB Output is correct
17 Correct 8 ms 8800 KB Output is correct
18 Correct 7 ms 8784 KB Output is correct
19 Correct 7 ms 8784 KB Output is correct
20 Correct 7 ms 9468 KB Output is correct
21 Correct 6 ms 9040 KB Output is correct
22 Correct 7 ms 8784 KB Output is correct
23 Correct 6 ms 8784 KB Output is correct
24 Correct 6 ms 8784 KB Output is correct
25 Correct 6 ms 8784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 7 ms 8784 KB Output is correct
3 Correct 7 ms 8776 KB Output is correct
4 Correct 8 ms 8784 KB Output is correct
5 Correct 7 ms 8784 KB Output is correct
6 Correct 8 ms 8952 KB Output is correct
7 Correct 7 ms 8996 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
9 Correct 1 ms 6480 KB Output is correct
10 Correct 2 ms 6480 KB Output is correct
11 Correct 1 ms 6480 KB Output is correct
12 Correct 1 ms 6480 KB Output is correct
13 Correct 1 ms 6480 KB Output is correct
14 Correct 7 ms 8992 KB Output is correct
15 Correct 7 ms 8784 KB Output is correct
16 Correct 7 ms 8784 KB Output is correct
17 Correct 8 ms 8800 KB Output is correct
18 Correct 7 ms 8784 KB Output is correct
19 Correct 7 ms 8784 KB Output is correct
20 Correct 7 ms 9468 KB Output is correct
21 Correct 6 ms 9040 KB Output is correct
22 Correct 7 ms 8784 KB Output is correct
23 Correct 6 ms 8784 KB Output is correct
24 Correct 6 ms 8784 KB Output is correct
25 Correct 6 ms 8784 KB Output is correct
26 Correct 1 ms 6480 KB Output is correct
27 Correct 197 ms 41952 KB Output is correct
28 Correct 205 ms 41876 KB Output is correct
29 Correct 207 ms 41796 KB Output is correct
30 Correct 201 ms 41544 KB Output is correct
31 Correct 208 ms 40348 KB Output is correct
32 Correct 197 ms 40264 KB Output is correct
33 Correct 1 ms 6644 KB Output is correct
34 Correct 1 ms 6480 KB Output is correct
35 Correct 1 ms 6480 KB Output is correct
36 Correct 2 ms 6480 KB Output is correct
37 Correct 1 ms 6480 KB Output is correct
38 Correct 1 ms 6480 KB Output is correct
39 Correct 193 ms 42192 KB Output is correct
40 Correct 188 ms 41800 KB Output is correct
41 Correct 184 ms 41684 KB Output is correct
42 Correct 182 ms 42312 KB Output is correct
43 Correct 193 ms 42056 KB Output is correct
44 Correct 166 ms 41800 KB Output is correct
45 Correct 152 ms 41420 KB Output is correct
46 Correct 189 ms 40532 KB Output is correct
47 Correct 173 ms 43848 KB Output is correct
48 Correct 189 ms 43856 KB Output is correct
49 Correct 188 ms 41540 KB Output is correct
50 Correct 194 ms 42056 KB Output is correct
51 Correct 203 ms 41060 KB Output is correct
52 Correct 188 ms 41544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 1 ms 6480 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 1 ms 6480 KB Output is correct
5 Correct 1 ms 6648 KB Output is correct
6 Correct 1 ms 6480 KB Output is correct
7 Correct 1 ms 6480 KB Output is correct
8 Correct 1 ms 6612 KB Output is correct
9 Correct 1 ms 6480 KB Output is correct
10 Correct 1 ms 6480 KB Output is correct
11 Correct 1 ms 6480 KB Output is correct
12 Correct 1 ms 6480 KB Output is correct
13 Correct 1 ms 6480 KB Output is correct
14 Correct 1 ms 6480 KB Output is correct
15 Correct 1 ms 6480 KB Output is correct
16 Correct 1 ms 6480 KB Output is correct
17 Correct 1 ms 6480 KB Output is correct
18 Correct 1 ms 6480 KB Output is correct
19 Correct 2 ms 6480 KB Output is correct
20 Correct 1 ms 6612 KB Output is correct
21 Correct 1 ms 6480 KB Output is correct
22 Correct 1 ms 6480 KB Output is correct
23 Correct 2 ms 6480 KB Output is correct
24 Correct 1 ms 6480 KB Output is correct
25 Correct 1 ms 6480 KB Output is correct
26 Correct 1 ms 6480 KB Output is correct
27 Correct 1 ms 6480 KB Output is correct
28 Correct 1 ms 6480 KB Output is correct
29 Correct 1 ms 6480 KB Output is correct
30 Correct 2 ms 6480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 1 ms 6480 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 1 ms 6480 KB Output is correct
5 Correct 1 ms 6648 KB Output is correct
6 Correct 1 ms 6480 KB Output is correct
7 Correct 1 ms 6480 KB Output is correct
8 Correct 1 ms 6612 KB Output is correct
9 Correct 1 ms 6480 KB Output is correct
10 Correct 1 ms 6480 KB Output is correct
11 Correct 1 ms 6480 KB Output is correct
12 Correct 1 ms 6480 KB Output is correct
13 Correct 1 ms 6480 KB Output is correct
14 Correct 1 ms 6480 KB Output is correct
15 Correct 1 ms 6480 KB Output is correct
16 Correct 1 ms 6480 KB Output is correct
17 Correct 7 ms 8784 KB Output is correct
18 Correct 7 ms 8776 KB Output is correct
19 Correct 8 ms 8784 KB Output is correct
20 Correct 7 ms 8784 KB Output is correct
21 Correct 8 ms 8952 KB Output is correct
22 Correct 7 ms 8996 KB Output is correct
23 Correct 2 ms 6480 KB Output is correct
24 Correct 1 ms 6480 KB Output is correct
25 Correct 2 ms 6480 KB Output is correct
26 Correct 1 ms 6480 KB Output is correct
27 Correct 1 ms 6480 KB Output is correct
28 Correct 1 ms 6480 KB Output is correct
29 Correct 7 ms 8992 KB Output is correct
30 Correct 7 ms 8784 KB Output is correct
31 Correct 7 ms 8784 KB Output is correct
32 Correct 8 ms 8800 KB Output is correct
33 Correct 7 ms 8784 KB Output is correct
34 Correct 7 ms 8784 KB Output is correct
35 Correct 7 ms 9468 KB Output is correct
36 Correct 6 ms 9040 KB Output is correct
37 Correct 7 ms 8784 KB Output is correct
38 Correct 6 ms 8784 KB Output is correct
39 Correct 6 ms 8784 KB Output is correct
40 Correct 6 ms 8784 KB Output is correct
41 Correct 2 ms 6480 KB Output is correct
42 Correct 8 ms 9040 KB Output is correct
43 Correct 8 ms 9040 KB Output is correct
44 Correct 8 ms 9212 KB Output is correct
45 Correct 8 ms 8964 KB Output is correct
46 Correct 8 ms 9040 KB Output is correct
47 Correct 7 ms 9040 KB Output is correct
48 Correct 1 ms 6492 KB Output is correct
49 Correct 1 ms 6480 KB Output is correct
50 Correct 1 ms 6480 KB Output is correct
51 Correct 1 ms 6480 KB Output is correct
52 Correct 1 ms 6480 KB Output is correct
53 Correct 1 ms 6480 KB Output is correct
54 Correct 7 ms 9040 KB Output is correct
55 Correct 9 ms 9040 KB Output is correct
56 Correct 7 ms 9040 KB Output is correct
57 Correct 8 ms 9308 KB Output is correct
58 Correct 7 ms 9040 KB Output is correct
59 Correct 7 ms 9212 KB Output is correct
60 Correct 6 ms 9040 KB Output is correct
61 Correct 6 ms 9040 KB Output is correct
62 Correct 8 ms 9040 KB Output is correct
63 Correct 8 ms 9040 KB Output is correct
64 Correct 10 ms 9040 KB Output is correct
65 Correct 8 ms 9268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 1 ms 6480 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 1 ms 6480 KB Output is correct
5 Correct 1 ms 6648 KB Output is correct
6 Correct 1 ms 6480 KB Output is correct
7 Correct 1 ms 6480 KB Output is correct
8 Correct 1 ms 6612 KB Output is correct
9 Correct 1 ms 6480 KB Output is correct
10 Correct 1 ms 6480 KB Output is correct
11 Correct 1 ms 6480 KB Output is correct
12 Correct 1 ms 6480 KB Output is correct
13 Correct 1 ms 6480 KB Output is correct
14 Correct 1 ms 6480 KB Output is correct
15 Correct 1 ms 6480 KB Output is correct
16 Correct 182 ms 37976 KB Output is correct
17 Correct 184 ms 37964 KB Output is correct
18 Correct 208 ms 37844 KB Output is correct
19 Correct 185 ms 37960 KB Output is correct
20 Correct 172 ms 37844 KB Output is correct
21 Correct 185 ms 37960 KB Output is correct
22 Correct 193 ms 37960 KB Output is correct
23 Correct 190 ms 37844 KB Output is correct
24 Correct 196 ms 37964 KB Output is correct
25 Correct 186 ms 37960 KB Output is correct
26 Correct 180 ms 37836 KB Output is correct
27 Correct 179 ms 37960 KB Output is correct
28 Correct 197 ms 37848 KB Output is correct
29 Correct 172 ms 37848 KB Output is correct
30 Correct 188 ms 37960 KB Output is correct
31 Correct 196 ms 37840 KB Output is correct
32 Correct 182 ms 37832 KB Output is correct
33 Correct 189 ms 37960 KB Output is correct
34 Correct 175 ms 37964 KB Output is correct
35 Correct 172 ms 38100 KB Output is correct
36 Correct 1 ms 6480 KB Output is correct
37 Correct 7 ms 8784 KB Output is correct
38 Correct 7 ms 8776 KB Output is correct
39 Correct 8 ms 8784 KB Output is correct
40 Correct 7 ms 8784 KB Output is correct
41 Correct 8 ms 8952 KB Output is correct
42 Correct 7 ms 8996 KB Output is correct
43 Correct 2 ms 6480 KB Output is correct
44 Correct 1 ms 6480 KB Output is correct
45 Correct 2 ms 6480 KB Output is correct
46 Correct 1 ms 6480 KB Output is correct
47 Correct 1 ms 6480 KB Output is correct
48 Correct 1 ms 6480 KB Output is correct
49 Correct 7 ms 8992 KB Output is correct
50 Correct 7 ms 8784 KB Output is correct
51 Correct 7 ms 8784 KB Output is correct
52 Correct 8 ms 8800 KB Output is correct
53 Correct 7 ms 8784 KB Output is correct
54 Correct 7 ms 8784 KB Output is correct
55 Correct 7 ms 9468 KB Output is correct
56 Correct 6 ms 9040 KB Output is correct
57 Correct 7 ms 8784 KB Output is correct
58 Correct 6 ms 8784 KB Output is correct
59 Correct 6 ms 8784 KB Output is correct
60 Correct 6 ms 8784 KB Output is correct
61 Correct 1 ms 6480 KB Output is correct
62 Correct 197 ms 41952 KB Output is correct
63 Correct 205 ms 41876 KB Output is correct
64 Correct 207 ms 41796 KB Output is correct
65 Correct 201 ms 41544 KB Output is correct
66 Correct 208 ms 40348 KB Output is correct
67 Correct 197 ms 40264 KB Output is correct
68 Correct 1 ms 6644 KB Output is correct
69 Correct 1 ms 6480 KB Output is correct
70 Correct 1 ms 6480 KB Output is correct
71 Correct 2 ms 6480 KB Output is correct
72 Correct 1 ms 6480 KB Output is correct
73 Correct 1 ms 6480 KB Output is correct
74 Correct 193 ms 42192 KB Output is correct
75 Correct 188 ms 41800 KB Output is correct
76 Correct 184 ms 41684 KB Output is correct
77 Correct 182 ms 42312 KB Output is correct
78 Correct 193 ms 42056 KB Output is correct
79 Correct 166 ms 41800 KB Output is correct
80 Correct 152 ms 41420 KB Output is correct
81 Correct 189 ms 40532 KB Output is correct
82 Correct 173 ms 43848 KB Output is correct
83 Correct 189 ms 43856 KB Output is correct
84 Correct 188 ms 41540 KB Output is correct
85 Correct 194 ms 42056 KB Output is correct
86 Correct 203 ms 41060 KB Output is correct
87 Correct 188 ms 41544 KB Output is correct
88 Correct 1 ms 6480 KB Output is correct
89 Correct 1 ms 6480 KB Output is correct
90 Correct 1 ms 6480 KB Output is correct
91 Correct 2 ms 6480 KB Output is correct
92 Correct 1 ms 6612 KB Output is correct
93 Correct 1 ms 6480 KB Output is correct
94 Correct 1 ms 6480 KB Output is correct
95 Correct 2 ms 6480 KB Output is correct
96 Correct 1 ms 6480 KB Output is correct
97 Correct 1 ms 6480 KB Output is correct
98 Correct 1 ms 6480 KB Output is correct
99 Correct 1 ms 6480 KB Output is correct
100 Correct 1 ms 6480 KB Output is correct
101 Correct 1 ms 6480 KB Output is correct
102 Correct 2 ms 6480 KB Output is correct
103 Correct 2 ms 6480 KB Output is correct
104 Correct 8 ms 9040 KB Output is correct
105 Correct 8 ms 9040 KB Output is correct
106 Correct 8 ms 9212 KB Output is correct
107 Correct 8 ms 8964 KB Output is correct
108 Correct 8 ms 9040 KB Output is correct
109 Correct 7 ms 9040 KB Output is correct
110 Correct 1 ms 6492 KB Output is correct
111 Correct 1 ms 6480 KB Output is correct
112 Correct 1 ms 6480 KB Output is correct
113 Correct 1 ms 6480 KB Output is correct
114 Correct 1 ms 6480 KB Output is correct
115 Correct 1 ms 6480 KB Output is correct
116 Correct 7 ms 9040 KB Output is correct
117 Correct 9 ms 9040 KB Output is correct
118 Correct 7 ms 9040 KB Output is correct
119 Correct 8 ms 9308 KB Output is correct
120 Correct 7 ms 9040 KB Output is correct
121 Correct 7 ms 9212 KB Output is correct
122 Correct 6 ms 9040 KB Output is correct
123 Correct 6 ms 9040 KB Output is correct
124 Correct 8 ms 9040 KB Output is correct
125 Correct 8 ms 9040 KB Output is correct
126 Correct 10 ms 9040 KB Output is correct
127 Correct 8 ms 9268 KB Output is correct
128 Correct 1 ms 6480 KB Output is correct
129 Correct 221 ms 45384 KB Output is correct
130 Correct 239 ms 44612 KB Output is correct
131 Correct 254 ms 42568 KB Output is correct
132 Correct 251 ms 44616 KB Output is correct
133 Correct 242 ms 45952 KB Output is correct
134 Correct 262 ms 46664 KB Output is correct
135 Correct 1 ms 6656 KB Output is correct
136 Correct 1 ms 6492 KB Output is correct
137 Correct 1 ms 6480 KB Output is correct
138 Correct 1 ms 6480 KB Output is correct
139 Correct 1 ms 6480 KB Output is correct
140 Correct 2 ms 6480 KB Output is correct
141 Correct 226 ms 46532 KB Output is correct
142 Correct 225 ms 46296 KB Output is correct
143 Correct 228 ms 42592 KB Output is correct
144 Correct 229 ms 46408 KB Output is correct
145 Correct 225 ms 44848 KB Output is correct
146 Correct 218 ms 44616 KB Output is correct
147 Correct 221 ms 42324 KB Output is correct
148 Correct 215 ms 45072 KB Output is correct
149 Correct 219 ms 42832 KB Output is correct
150 Correct 183 ms 46152 KB Output is correct
151 Correct 185 ms 46472 KB Output is correct
152 Correct 226 ms 45892 KB Output is correct
153 Correct 244 ms 45896 KB Output is correct
154 Correct 227 ms 45384 KB Output is correct
155 Correct 241 ms 45592 KB Output is correct