//Suleyman Atayew
#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <bitset>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#define N 200010
#define ff first
#define ss second
#define pb push_back
#define ll long long
#define mod 1000000007
#define pii pair <int, int>
#define sz(a) (int)(a.size())
ll bigmod(ll a, ll b) { if(b==0)return 1; ll ret = bigmod(a, b/2); return ret * ret % mod * (b%2 ? a : 1) % mod; }
using namespace std;
pii p[N];
int n, m, sz;
map <int, int> M;
int v[N];
pii T[N*4];
priority_queue <int> Q[N*4];
void upd(int pos, pii x, int l, int r, int node)
{
if(l == r) {
if(x.ff) {
Q[node].push(x.ss);
T[node] = {pos, Q[node].top()};
} else {
Q[node].pop();
if(!Q[node].empty())
T[node] = {pos, Q[node].top()};
else
T[node] = {0, 0};
}
return;
}
if(pos <= (l+r)/2)
upd(pos, x, l, (l+r)/2, node*2);
else
upd(pos, x, (l+r)/2+1, r, node*2+1);
if(T[node*2].ss > T[node*2+1].ss)
T[node] = T[node*2];
else
T[node] = T[node*2+1];
}
pii tap(int pos, int l, int r, int node)
{
if(l > pos) return {0, 0};
if(r <= pos) return {T[node].ss, T[node].ff};
return max(tap(pos, l, (l+r)/2, node*2), tap(pos, (l+r)/2+1, r, node*2+1));
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
vector <int> E;
for(int i = 1; i <= n; i++) {
int a, b;
cin >> a >> b;
M[a] = 1;
p[i] = {a, b};
}
for(int i = 1; i <= m; i++)
cin >> v[i], M[v[i]] = 1;
for(auto &i: M) i.ss = ++sz;
sort(v+1, v+1+m);
for(int i = 1; i <= n; i++)
upd(M[p[i].ff], {1, p[i].ss}, 1, sz, 1);
for(int i = m; i >= 0; i--) {
int x = M[v[i]];
pii ans = tap(x, 1, sz, 1);
if(ans.ss == 0 || !i) {
cout << m-i;
return 0;
}
upd(ans.ss, {0, ans.ff}, 1, sz, 1);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
25292 KB |
Output is correct |
2 |
Correct |
15 ms |
25292 KB |
Output is correct |
3 |
Correct |
15 ms |
25292 KB |
Output is correct |
4 |
Correct |
16 ms |
25380 KB |
Output is correct |
5 |
Correct |
17 ms |
25388 KB |
Output is correct |
6 |
Correct |
15 ms |
25292 KB |
Output is correct |
7 |
Correct |
14 ms |
25292 KB |
Output is correct |
8 |
Correct |
15 ms |
25292 KB |
Output is correct |
9 |
Correct |
15 ms |
25364 KB |
Output is correct |
10 |
Correct |
15 ms |
25292 KB |
Output is correct |
11 |
Correct |
17 ms |
25292 KB |
Output is correct |
12 |
Correct |
14 ms |
25292 KB |
Output is correct |
13 |
Correct |
15 ms |
25364 KB |
Output is correct |
14 |
Correct |
14 ms |
25388 KB |
Output is correct |
15 |
Correct |
15 ms |
25308 KB |
Output is correct |
16 |
Correct |
18 ms |
25384 KB |
Output is correct |
17 |
Correct |
16 ms |
25300 KB |
Output is correct |
18 |
Correct |
15 ms |
25292 KB |
Output is correct |
19 |
Correct |
15 ms |
25380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
25292 KB |
Output is correct |
2 |
Correct |
15 ms |
25292 KB |
Output is correct |
3 |
Correct |
15 ms |
25292 KB |
Output is correct |
4 |
Correct |
16 ms |
25380 KB |
Output is correct |
5 |
Correct |
17 ms |
25388 KB |
Output is correct |
6 |
Correct |
15 ms |
25292 KB |
Output is correct |
7 |
Correct |
14 ms |
25292 KB |
Output is correct |
8 |
Correct |
15 ms |
25292 KB |
Output is correct |
9 |
Correct |
15 ms |
25364 KB |
Output is correct |
10 |
Correct |
15 ms |
25292 KB |
Output is correct |
11 |
Correct |
17 ms |
25292 KB |
Output is correct |
12 |
Correct |
14 ms |
25292 KB |
Output is correct |
13 |
Correct |
15 ms |
25364 KB |
Output is correct |
14 |
Correct |
14 ms |
25388 KB |
Output is correct |
15 |
Correct |
15 ms |
25308 KB |
Output is correct |
16 |
Correct |
18 ms |
25384 KB |
Output is correct |
17 |
Correct |
16 ms |
25300 KB |
Output is correct |
18 |
Correct |
15 ms |
25292 KB |
Output is correct |
19 |
Correct |
15 ms |
25380 KB |
Output is correct |
20 |
Correct |
16 ms |
25532 KB |
Output is correct |
21 |
Correct |
16 ms |
25420 KB |
Output is correct |
22 |
Correct |
16 ms |
25524 KB |
Output is correct |
23 |
Correct |
17 ms |
25532 KB |
Output is correct |
24 |
Correct |
18 ms |
25420 KB |
Output is correct |
25 |
Correct |
17 ms |
25524 KB |
Output is correct |
26 |
Correct |
17 ms |
25572 KB |
Output is correct |
27 |
Correct |
19 ms |
25540 KB |
Output is correct |
28 |
Correct |
18 ms |
25524 KB |
Output is correct |
29 |
Correct |
16 ms |
25392 KB |
Output is correct |
30 |
Correct |
17 ms |
25520 KB |
Output is correct |
31 |
Correct |
15 ms |
25420 KB |
Output is correct |
32 |
Correct |
15 ms |
25480 KB |
Output is correct |
33 |
Correct |
18 ms |
25440 KB |
Output is correct |
34 |
Correct |
18 ms |
25548 KB |
Output is correct |
35 |
Correct |
17 ms |
25392 KB |
Output is correct |
36 |
Correct |
17 ms |
25548 KB |
Output is correct |
37 |
Correct |
16 ms |
25548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
25292 KB |
Output is correct |
2 |
Correct |
15 ms |
25292 KB |
Output is correct |
3 |
Correct |
15 ms |
25292 KB |
Output is correct |
4 |
Correct |
16 ms |
25380 KB |
Output is correct |
5 |
Correct |
17 ms |
25388 KB |
Output is correct |
6 |
Correct |
15 ms |
25292 KB |
Output is correct |
7 |
Correct |
14 ms |
25292 KB |
Output is correct |
8 |
Correct |
15 ms |
25292 KB |
Output is correct |
9 |
Correct |
15 ms |
25364 KB |
Output is correct |
10 |
Correct |
15 ms |
25292 KB |
Output is correct |
11 |
Correct |
17 ms |
25292 KB |
Output is correct |
12 |
Correct |
14 ms |
25292 KB |
Output is correct |
13 |
Correct |
15 ms |
25364 KB |
Output is correct |
14 |
Correct |
14 ms |
25388 KB |
Output is correct |
15 |
Correct |
15 ms |
25308 KB |
Output is correct |
16 |
Correct |
18 ms |
25384 KB |
Output is correct |
17 |
Correct |
16 ms |
25300 KB |
Output is correct |
18 |
Correct |
15 ms |
25292 KB |
Output is correct |
19 |
Correct |
15 ms |
25380 KB |
Output is correct |
20 |
Correct |
16 ms |
25532 KB |
Output is correct |
21 |
Correct |
16 ms |
25420 KB |
Output is correct |
22 |
Correct |
16 ms |
25524 KB |
Output is correct |
23 |
Correct |
17 ms |
25532 KB |
Output is correct |
24 |
Correct |
18 ms |
25420 KB |
Output is correct |
25 |
Correct |
17 ms |
25524 KB |
Output is correct |
26 |
Correct |
17 ms |
25572 KB |
Output is correct |
27 |
Correct |
19 ms |
25540 KB |
Output is correct |
28 |
Correct |
18 ms |
25524 KB |
Output is correct |
29 |
Correct |
16 ms |
25392 KB |
Output is correct |
30 |
Correct |
17 ms |
25520 KB |
Output is correct |
31 |
Correct |
15 ms |
25420 KB |
Output is correct |
32 |
Correct |
15 ms |
25480 KB |
Output is correct |
33 |
Correct |
18 ms |
25440 KB |
Output is correct |
34 |
Correct |
18 ms |
25548 KB |
Output is correct |
35 |
Correct |
17 ms |
25392 KB |
Output is correct |
36 |
Correct |
17 ms |
25548 KB |
Output is correct |
37 |
Correct |
16 ms |
25548 KB |
Output is correct |
38 |
Correct |
351 ms |
39316 KB |
Output is correct |
39 |
Correct |
117 ms |
30084 KB |
Output is correct |
40 |
Correct |
87 ms |
30020 KB |
Output is correct |
41 |
Correct |
220 ms |
34292 KB |
Output is correct |
42 |
Correct |
304 ms |
43968 KB |
Output is correct |
43 |
Correct |
263 ms |
44028 KB |
Output is correct |
44 |
Correct |
266 ms |
39264 KB |
Output is correct |
45 |
Correct |
394 ms |
46036 KB |
Output is correct |
46 |
Correct |
297 ms |
39320 KB |
Output is correct |
47 |
Correct |
394 ms |
44232 KB |
Output is correct |
48 |
Correct |
215 ms |
36804 KB |
Output is correct |
49 |
Correct |
330 ms |
42992 KB |
Output is correct |
50 |
Correct |
215 ms |
36188 KB |
Output is correct |
51 |
Correct |
277 ms |
43968 KB |
Output is correct |
52 |
Correct |
304 ms |
44148 KB |
Output is correct |
53 |
Correct |
310 ms |
44940 KB |
Output is correct |
54 |
Correct |
74 ms |
30012 KB |
Output is correct |
55 |
Correct |
486 ms |
46052 KB |
Output is correct |
56 |
Correct |
232 ms |
37952 KB |
Output is correct |
57 |
Correct |
88 ms |
31412 KB |
Output is correct |
58 |
Correct |
55 ms |
28720 KB |
Output is correct |
59 |
Correct |
242 ms |
37928 KB |
Output is correct |
60 |
Correct |
93 ms |
32760 KB |
Output is correct |
61 |
Correct |
211 ms |
39136 KB |
Output is correct |
62 |
Correct |
427 ms |
46012 KB |
Output is correct |
63 |
Correct |
412 ms |
46016 KB |
Output is correct |
64 |
Correct |
465 ms |
46148 KB |
Output is correct |
65 |
Correct |
444 ms |
45976 KB |
Output is correct |
66 |
Correct |
446 ms |
46072 KB |
Output is correct |
67 |
Correct |
455 ms |
46068 KB |
Output is correct |
68 |
Correct |
463 ms |
46068 KB |
Output is correct |
69 |
Correct |
292 ms |
34736 KB |
Output is correct |
70 |
Correct |
412 ms |
46068 KB |
Output is correct |
71 |
Correct |
160 ms |
30412 KB |
Output is correct |
72 |
Correct |
205 ms |
32084 KB |
Output is correct |
73 |
Correct |
108 ms |
29884 KB |
Output is correct |