This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |