记录编号 203798 评测结果 AAAAAAAAAA
题目名称 平凡的题面 最终得分 100
用户昵称 GravatarTychus 是否通过 通过
代码语言 C++ 运行时间 0.269 s
提交时间 2015-11-03 17:26:29 内存使用 1.93 MiB
显示代码纯文本
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <string>
#include <cmath>
#include <queue>
#define MAXN 100000
using namespace std;
struct line
{
	int l,r;
	friend bool operator < (line n1,line n2)
	{
		return n1.r>n2.r;
	}
}e[100010];
int n,m,ans=0,a[100010],b[100010],t1=1,t2=1;
bool flag[100010];
priority_queue<line> Q;
bool cmp(line a,line b)
{
	return a.l<b.l;
}
int main()
{
	freopen("bg.in","r",stdin);
	freopen("bg.out","w",stdout);
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for (int i=1;i<=n;i++)
		cin>>a[i];
	for (int i=1;i<=m;i++)
		cin>>e[i].l>>e[i].r;
	sort(a+1,a+n+1);
	sort(e+1,e+m+1,cmp);
	for (int i=1;i<=MAXN;i++)
	{
		while (i>a[t2]&&t2<=n) t2++;
		while (!Q.empty()&&Q.top().r<i) Q.pop();
		while (i==e[t1].l&&t1<=m) Q.push(e[t1++]);
		while (i==a[t2]&&t2<=n&&!Q.empty())
		{
			ans++;
			Q.pop();
			t2++;
		}
		if (t2>n) break;
	}
	cout<<ans<<endl;
	fclose(stdin);
	fclose(stdout);
	return 0;
}