#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 1e5 + 10;
pair<int, int> a[4*MAXN];
void update(int l, int r, int tar, int idx, int val) {
if(l == r) {
a[idx] = {val, tar};
return;
}
int mid = (l+r) / 2;
if(tar <= mid) update(l, mid, tar, 2*idx+1, val);
else update(mid+1, r, tar, 2*idx+2, val);
a[idx] = max(a[2*idx+1], a[2*idx+2]);
}
pair<int, int> query(int l, int r, int constl, int constr, int idx) {
if(l <= constl && constr <= r) return a[idx];
int mid = (constl + constr) / 2;
if(mid < l || r < constl) return query(l, r, mid+1, constr, 2*idx+2);
else if(constr < l || r < mid+1) return query(l, r, constl, mid, 2*idx+1);
else return max(query(l, r, constl, mid, 2*idx+1), query(l, r, mid+1, constr, 2*idx+2));
}
signed main() {
int N, M; cin >> N >> M;
pair<int, int> p[N+1]; for(int i=1; i<=N; i++) cin >> p[i].first >> p[i].second;
int c[M+1]; for(int i=1; i<=M; i++) cin >> c[i];
sort(p+1, p+N+1);
sort(c+1, c+M+1);
for(int i=1; i<=N; i++) update(1, N, i, 0, p[i].second);
vector<int> v;
for(int i=M; i>=1; i--) {
int lb = 1, rb = N;
while(lb < rb) {
int mid = (lb+rb+1) / 2;
if(p[mid].first <= c[i]) lb = mid;
else rb = mid-1;
}
if(p[lb].first <= c[i]) {
pair<int, int> res = query(1, lb, 1, N, 0);
if(v.size() && res.first > v.back()) return cout << M-i << '\n', 0;
if(res.first == 0) return cout << M-i << '\n', 0;
update(1, N, res.second, 0, 0);
}
else {
return cout << M-i << '\n', 0;
}
}
cout << M << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
300 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
300 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
2 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
2 ms |
332 KB |
Output is correct |
37 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
300 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
2 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
2 ms |
332 KB |
Output is correct |
37 |
Correct |
2 ms |
332 KB |
Output is correct |
38 |
Correct |
155 ms |
9632 KB |
Output is correct |
39 |
Correct |
152 ms |
9608 KB |
Output is correct |
40 |
Correct |
145 ms |
9640 KB |
Output is correct |
41 |
Correct |
163 ms |
9504 KB |
Output is correct |
42 |
Correct |
131 ms |
9540 KB |
Output is correct |
43 |
Correct |
129 ms |
9612 KB |
Output is correct |
44 |
Correct |
142 ms |
9512 KB |
Output is correct |
45 |
Correct |
173 ms |
9740 KB |
Output is correct |
46 |
Correct |
155 ms |
9540 KB |
Output is correct |
47 |
Correct |
146 ms |
9028 KB |
Output is correct |
48 |
Correct |
136 ms |
9004 KB |
Output is correct |
49 |
Correct |
134 ms |
8520 KB |
Output is correct |
50 |
Correct |
119 ms |
8528 KB |
Output is correct |
51 |
Correct |
132 ms |
9640 KB |
Output is correct |
52 |
Correct |
132 ms |
9640 KB |
Output is correct |
53 |
Correct |
130 ms |
9512 KB |
Output is correct |
54 |
Correct |
151 ms |
9636 KB |
Output is correct |
55 |
Correct |
157 ms |
9644 KB |
Output is correct |
56 |
Correct |
91 ms |
7868 KB |
Output is correct |
57 |
Correct |
41 ms |
1988 KB |
Output is correct |
58 |
Correct |
95 ms |
7816 KB |
Output is correct |
59 |
Correct |
92 ms |
7876 KB |
Output is correct |
60 |
Correct |
42 ms |
2072 KB |
Output is correct |
61 |
Correct |
84 ms |
5188 KB |
Output is correct |
62 |
Correct |
156 ms |
9516 KB |
Output is correct |
63 |
Correct |
157 ms |
9540 KB |
Output is correct |
64 |
Correct |
157 ms |
9516 KB |
Output is correct |
65 |
Correct |
158 ms |
9628 KB |
Output is correct |
66 |
Correct |
154 ms |
9524 KB |
Output is correct |
67 |
Correct |
158 ms |
9552 KB |
Output is correct |
68 |
Correct |
156 ms |
9540 KB |
Output is correct |
69 |
Correct |
161 ms |
9636 KB |
Output is correct |
70 |
Correct |
156 ms |
9540 KB |
Output is correct |
71 |
Correct |
154 ms |
9540 KB |
Output is correct |
72 |
Correct |
154 ms |
9644 KB |
Output is correct |
73 |
Correct |
150 ms |
9632 KB |
Output is correct |