显示代码纯文本
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<cstring>
#include<string>
#include<cstdlib>
using namespace std;
int l[100010];
int n,m;
struct str{
int zuo,you;
}a[100010];
int cmp(const str a1,const str b)
{
if(a1.you<b.you) return 1;
if(a1.you==b.you&&a1.zuo<b.zuo) return 1;
return 0;
}
int main()
{
freopen("bg.in","r",stdin);
freopen("bg.out","w",stdout);
int ans=0;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>l[i];
}
sort(l+1,l+1+n);
for(int i=1;i<=m;i++)
{
cin>>a[i].zuo>>a[i].you;
// cout<<i<<endl;
// printf("%d %d\n",a[i].zuo,a[i].you);
}
sort(a+1,a+1+m,cmp);
for(int i=1,j=1;;)
{
if(i>n||j>m) break;
if(l[i]<a[j].zuo)
{
i++;
continue;
}
if(l[i]>a[j].you)
{
j++;
continue;
}
if(l[i]>=a[j].zuo&&l[i]<=a[j].you)
{
ans++;
i++;
j++;
continue;
}
}
cout<<ans;
return 0;
}