#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> seg;
void build() {
for(int i=n-1;i>0;i--) seg[i]=max(seg[i<<1],seg[i<<1|1]);
}
void modify(int p, int value) {
for(seg[p+=n]=value;p>1;p>>=1) seg[p>>1]=max(seg[p],seg[p^1]);
}
int query(int l, int r){ // remember, this works over range [l,r)
int res=-1;
for(l+=n,r+=n;l<r;l>>=1,r>>=1){
if(l&1) res=max(res,seg[l++]); //remember, this needs to be l++, ++l will WA
if(r&1) res=max(res,seg[--r]);
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int m;
cin>>n>>m;
vector<pair<int,int>> pics(n);
seg.resize(2*n);
vector<int> frames(m);
for (int i=0;i<n;i++){
int a,b;
cin>>a>>b;
pics[i]={a,b};
}
sort(pics.begin(),pics.end());
for(int i=0;i<m;i++){
cin>>frames[i];
}
sort(frames.begin(),frames.end());
vector<tuple<int,int,int>> values(n);
for (int i=0;i<n;i++){
values[i]={pics[i].second,pics[i].first,i};
}
for (int i=0;i<n;i++){
seg[n+i]=pics[i].second;
}
sort(values.begin(),values.end());
build();
int res=0;
//O(n+nlogn+m+mlogm+nlogn)
for(int i=m-1;i>=0;i--){
auto it=upper_bound(pics.begin(),pics.end(),make_pair(frames[i],(int)1e9+1));
if(it==pics.begin()){
break;
}
int r=it-pics.begin();
// cerr<<r<<"\n";
int k = query(0,r);
// cerr<<k<<"\n";
if(k==-1){
break;
}
res++;
tuple<int,int,int> cur={k,frames[i],n+1};
auto it2=upper_bound(values.begin(),values.end(),cur);
it2--;
int sec=get<2>(*it2);
modify(sec,-1);
values.erase(it2);
}
cout<<res<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 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 |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 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 |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 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 |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
51 ms |
3408 KB |
Output is correct |
39 |
Correct |
46 ms |
6492 KB |
Output is correct |
40 |
Correct |
42 ms |
6680 KB |
Output is correct |
41 |
Correct |
52 ms |
6228 KB |
Output is correct |
42 |
Correct |
37 ms |
6248 KB |
Output is correct |
43 |
Correct |
38 ms |
6348 KB |
Output is correct |
44 |
Correct |
44 ms |
6480 KB |
Output is correct |
45 |
Correct |
58 ms |
6228 KB |
Output is correct |
46 |
Correct |
51 ms |
6364 KB |
Output is correct |
47 |
Correct |
611 ms |
6128 KB |
Output is correct |
48 |
Correct |
597 ms |
6224 KB |
Output is correct |
49 |
Correct |
42 ms |
4948 KB |
Output is correct |
50 |
Correct |
41 ms |
4948 KB |
Output is correct |
51 |
Correct |
43 ms |
6380 KB |
Output is correct |
52 |
Correct |
44 ms |
6380 KB |
Output is correct |
53 |
Correct |
49 ms |
6252 KB |
Output is correct |
54 |
Correct |
41 ms |
6504 KB |
Output is correct |
55 |
Correct |
80 ms |
6484 KB |
Output is correct |
56 |
Correct |
30 ms |
4956 KB |
Output is correct |
57 |
Correct |
14 ms |
1628 KB |
Output is correct |
58 |
Correct |
27 ms |
4944 KB |
Output is correct |
59 |
Correct |
31 ms |
4944 KB |
Output is correct |
60 |
Correct |
14 ms |
1752 KB |
Output is correct |
61 |
Correct |
74 ms |
3412 KB |
Output is correct |
62 |
Correct |
643 ms |
6480 KB |
Output is correct |
63 |
Correct |
645 ms |
6484 KB |
Output is correct |
64 |
Correct |
652 ms |
6480 KB |
Output is correct |
65 |
Correct |
654 ms |
6480 KB |
Output is correct |
66 |
Correct |
661 ms |
6632 KB |
Output is correct |
67 |
Correct |
646 ms |
6484 KB |
Output is correct |
68 |
Correct |
648 ms |
6476 KB |
Output is correct |
69 |
Correct |
655 ms |
6480 KB |
Output is correct |
70 |
Correct |
642 ms |
6740 KB |
Output is correct |
71 |
Correct |
652 ms |
6484 KB |
Output is correct |
72 |
Correct |
657 ms |
6484 KB |
Output is correct |
73 |
Correct |
632 ms |
6484 KB |
Output is correct |