#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
typedef int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;
ii segt2[8*100100];
vector<ii> arr(100001);
int fr[100001];
void up2(int node,int l,int r,int in,ii val)
{
if(l==r)
{
segt2[node]=val;
return;
}
int m=(l+r)/2;
if(in<=m)
up2(2*node+1,l,m,in,val);
else
up2(2*node+2,m+1,r,in,val);
segt2[node]=max(segt2[2*node+1],segt2[2*node+2]);
}
ii qu2(int node,int l,int r,int s,int e)
{
if(r<s||l>e)
return(mp(-1,-1));
if(l>=s&&r<=e)
return(segt2[node]);
int m=(l+r)/2;
ii q1=qu2(2*node+1,l,m,s,e),q2=qu2(2*node+2,m+1,r,s,e);
return(max(q1,q2));
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lli test=1;
for(int i=0;i<8*100100;++i)
segt2[i]=mp(-1,-1);
for(;test>0;--test)
{
int n,m;
cin>>n>>m;
for(int i=0;i<n;++i)
{
int f,s;
cin>>f>>s;
arr[i]=mp(f,s);
}
for(int i=0;i<m;++i)
cin>>fr[i];
sort((arr.begin()),arr.begin()+n);
sort(fr,fr+m);
for(int i=0;i<n;++i)
up2(0,0,m+n+1,i,mp(arr[i].S,i));
lli ma=0;
for(int i=m-1;i>=0;--i)
{
auto it=upper_bound(arr.begin(),arr.begin()+n,mp(fr[i],1000100000))-arr.begin();
it--;
if(it!=-1)
{
ii sl=qu2(0,0,m+n+1,0,it);
if(sl.S!=-1)
{
up2(0,0,m+n+1,sl.S,mp(-1,-1));
ma++;
}
}
}
cout<<ma<<endl;
}
return(0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
7424 KB |
Output is correct |
2 |
Correct |
8 ms |
7424 KB |
Output is correct |
3 |
Correct |
8 ms |
7424 KB |
Output is correct |
4 |
Correct |
8 ms |
7424 KB |
Output is correct |
5 |
Correct |
8 ms |
7424 KB |
Output is correct |
6 |
Correct |
8 ms |
7424 KB |
Output is correct |
7 |
Correct |
8 ms |
7424 KB |
Output is correct |
8 |
Correct |
8 ms |
7424 KB |
Output is correct |
9 |
Correct |
8 ms |
7424 KB |
Output is correct |
10 |
Correct |
10 ms |
7424 KB |
Output is correct |
11 |
Correct |
8 ms |
7424 KB |
Output is correct |
12 |
Correct |
8 ms |
7424 KB |
Output is correct |
13 |
Correct |
8 ms |
7424 KB |
Output is correct |
14 |
Correct |
8 ms |
7424 KB |
Output is correct |
15 |
Correct |
8 ms |
7424 KB |
Output is correct |
16 |
Correct |
9 ms |
7424 KB |
Output is correct |
17 |
Correct |
8 ms |
7424 KB |
Output is correct |
18 |
Correct |
8 ms |
7424 KB |
Output is correct |
19 |
Correct |
8 ms |
7424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
7424 KB |
Output is correct |
2 |
Correct |
8 ms |
7424 KB |
Output is correct |
3 |
Correct |
8 ms |
7424 KB |
Output is correct |
4 |
Correct |
8 ms |
7424 KB |
Output is correct |
5 |
Correct |
8 ms |
7424 KB |
Output is correct |
6 |
Correct |
8 ms |
7424 KB |
Output is correct |
7 |
Correct |
8 ms |
7424 KB |
Output is correct |
8 |
Correct |
8 ms |
7424 KB |
Output is correct |
9 |
Correct |
8 ms |
7424 KB |
Output is correct |
10 |
Correct |
10 ms |
7424 KB |
Output is correct |
11 |
Correct |
8 ms |
7424 KB |
Output is correct |
12 |
Correct |
8 ms |
7424 KB |
Output is correct |
13 |
Correct |
8 ms |
7424 KB |
Output is correct |
14 |
Correct |
8 ms |
7424 KB |
Output is correct |
15 |
Correct |
8 ms |
7424 KB |
Output is correct |
16 |
Correct |
9 ms |
7424 KB |
Output is correct |
17 |
Correct |
8 ms |
7424 KB |
Output is correct |
18 |
Correct |
8 ms |
7424 KB |
Output is correct |
19 |
Correct |
8 ms |
7424 KB |
Output is correct |
20 |
Correct |
9 ms |
7424 KB |
Output is correct |
21 |
Correct |
9 ms |
7496 KB |
Output is correct |
22 |
Correct |
9 ms |
7552 KB |
Output is correct |
23 |
Correct |
9 ms |
7424 KB |
Output is correct |
24 |
Correct |
9 ms |
7424 KB |
Output is correct |
25 |
Correct |
10 ms |
7424 KB |
Output is correct |
26 |
Correct |
9 ms |
7424 KB |
Output is correct |
27 |
Correct |
10 ms |
7424 KB |
Output is correct |
28 |
Correct |
10 ms |
7424 KB |
Output is correct |
29 |
Correct |
10 ms |
7424 KB |
Output is correct |
30 |
Correct |
10 ms |
7424 KB |
Output is correct |
31 |
Correct |
9 ms |
7424 KB |
Output is correct |
32 |
Correct |
10 ms |
7424 KB |
Output is correct |
33 |
Correct |
9 ms |
7424 KB |
Output is correct |
34 |
Correct |
9 ms |
7424 KB |
Output is correct |
35 |
Correct |
9 ms |
7424 KB |
Output is correct |
36 |
Correct |
9 ms |
7424 KB |
Output is correct |
37 |
Correct |
9 ms |
7424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
7424 KB |
Output is correct |
2 |
Correct |
8 ms |
7424 KB |
Output is correct |
3 |
Correct |
8 ms |
7424 KB |
Output is correct |
4 |
Correct |
8 ms |
7424 KB |
Output is correct |
5 |
Correct |
8 ms |
7424 KB |
Output is correct |
6 |
Correct |
8 ms |
7424 KB |
Output is correct |
7 |
Correct |
8 ms |
7424 KB |
Output is correct |
8 |
Correct |
8 ms |
7424 KB |
Output is correct |
9 |
Correct |
8 ms |
7424 KB |
Output is correct |
10 |
Correct |
10 ms |
7424 KB |
Output is correct |
11 |
Correct |
8 ms |
7424 KB |
Output is correct |
12 |
Correct |
8 ms |
7424 KB |
Output is correct |
13 |
Correct |
8 ms |
7424 KB |
Output is correct |
14 |
Correct |
8 ms |
7424 KB |
Output is correct |
15 |
Correct |
8 ms |
7424 KB |
Output is correct |
16 |
Correct |
9 ms |
7424 KB |
Output is correct |
17 |
Correct |
8 ms |
7424 KB |
Output is correct |
18 |
Correct |
8 ms |
7424 KB |
Output is correct |
19 |
Correct |
8 ms |
7424 KB |
Output is correct |
20 |
Correct |
9 ms |
7424 KB |
Output is correct |
21 |
Correct |
9 ms |
7496 KB |
Output is correct |
22 |
Correct |
9 ms |
7552 KB |
Output is correct |
23 |
Correct |
9 ms |
7424 KB |
Output is correct |
24 |
Correct |
9 ms |
7424 KB |
Output is correct |
25 |
Correct |
10 ms |
7424 KB |
Output is correct |
26 |
Correct |
9 ms |
7424 KB |
Output is correct |
27 |
Correct |
10 ms |
7424 KB |
Output is correct |
28 |
Correct |
10 ms |
7424 KB |
Output is correct |
29 |
Correct |
10 ms |
7424 KB |
Output is correct |
30 |
Correct |
10 ms |
7424 KB |
Output is correct |
31 |
Correct |
9 ms |
7424 KB |
Output is correct |
32 |
Correct |
10 ms |
7424 KB |
Output is correct |
33 |
Correct |
9 ms |
7424 KB |
Output is correct |
34 |
Correct |
9 ms |
7424 KB |
Output is correct |
35 |
Correct |
9 ms |
7424 KB |
Output is correct |
36 |
Correct |
9 ms |
7424 KB |
Output is correct |
37 |
Correct |
9 ms |
7424 KB |
Output is correct |
38 |
Correct |
119 ms |
10744 KB |
Output is correct |
39 |
Correct |
111 ms |
10744 KB |
Output is correct |
40 |
Correct |
101 ms |
10744 KB |
Output is correct |
41 |
Correct |
118 ms |
10744 KB |
Output is correct |
42 |
Correct |
81 ms |
10664 KB |
Output is correct |
43 |
Correct |
84 ms |
10872 KB |
Output is correct |
44 |
Correct |
110 ms |
10744 KB |
Output is correct |
45 |
Correct |
132 ms |
10616 KB |
Output is correct |
46 |
Correct |
119 ms |
10616 KB |
Output is correct |
47 |
Correct |
111 ms |
10232 KB |
Output is correct |
48 |
Correct |
101 ms |
10232 KB |
Output is correct |
49 |
Correct |
108 ms |
10104 KB |
Output is correct |
50 |
Correct |
95 ms |
10112 KB |
Output is correct |
51 |
Correct |
92 ms |
10744 KB |
Output is correct |
52 |
Correct |
102 ms |
10872 KB |
Output is correct |
53 |
Correct |
100 ms |
10616 KB |
Output is correct |
54 |
Correct |
103 ms |
10744 KB |
Output is correct |
55 |
Correct |
115 ms |
10744 KB |
Output is correct |
56 |
Correct |
62 ms |
9336 KB |
Output is correct |
57 |
Correct |
37 ms |
8824 KB |
Output is correct |
58 |
Correct |
71 ms |
9336 KB |
Output is correct |
59 |
Correct |
60 ms |
9336 KB |
Output is correct |
60 |
Correct |
45 ms |
8824 KB |
Output is correct |
61 |
Correct |
72 ms |
9464 KB |
Output is correct |
62 |
Correct |
118 ms |
10744 KB |
Output is correct |
63 |
Correct |
120 ms |
10616 KB |
Output is correct |
64 |
Correct |
125 ms |
10616 KB |
Output is correct |
65 |
Correct |
124 ms |
10744 KB |
Output is correct |
66 |
Correct |
126 ms |
10744 KB |
Output is correct |
67 |
Correct |
122 ms |
10744 KB |
Output is correct |
68 |
Correct |
126 ms |
10640 KB |
Output is correct |
69 |
Correct |
124 ms |
10636 KB |
Output is correct |
70 |
Correct |
123 ms |
10872 KB |
Output is correct |
71 |
Correct |
117 ms |
10744 KB |
Output is correct |
72 |
Correct |
119 ms |
10744 KB |
Output is correct |
73 |
Correct |
113 ms |
10744 KB |
Output is correct |