比赛 20170912 评测结果 AAAAAAAAAA
题目名称 平凡的题面 最终得分 100
用户昵称 AAAAAAAAAA 运行时间 0.155 s
代码语言 C++ 内存使用 1.48 MiB
提交时间 2017-09-12 20:12:34
显示代码纯文本
#define _CRT_SECURE_NO_WARNINGS
#include<queue>
#include<algorithm>
#include<cstdio>
#define MAXN 100010
namespace IO {
	char buf[1 << 15], *fs, *ft;
	inline char gc() { return (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 15, stdin), fs == ft)) ? 0 : *fs++; }
	inline int qr() {
		int x = 0, ch = gc();
		while (ch<'0' || ch>'9') { ch = gc(); }
		while (ch >= '0'&&ch <= '9') { x = (x << 1) + (x << 3) + ch - '0'; ch = gc(); }
		return x;
	}
}using namespace IO;
using namespace std;
struct Seg {
	int l, r;
}seg[MAXN];
bool operator < (Seg x, Seg y) { return x.r>y.r; }
bool cmp(Seg x, Seg y) {
	if (x.l == y.l)return x.r<y.r;
	return x.l<y.l;
}
priority_queue<Seg>q;
int N, M, len[MAXN], ans;
int main() {
	freopen("bg.in", "r", stdin);
	freopen("bg.out", "w", stdout);
	N = qr(); M = qr();
	for (int i = 1; i <= N; i++)len[i] = qr();
	for (int i = 1; i <= M; i++)seg[i].l = qr(), seg[i].r = qr();
	sort(len + 1, len + 1 + N);
	sort(seg + 1, seg + 1 + M, cmp);
	int now = 1;
	for (int i = 1; i <= N; i++) {
		if (now <= M) {
			do {
				if (seg[now].l > len[i])break;
				if (seg[now].r >= len[i])q.push(seg[now]);
				now++;
			} while (now <= M);
		}
		if (q.empty())continue;
		while (q.top().r < len[i] && !q.empty()) {
			q.pop();
			if (q.empty())break;
		}
		if (q.empty())continue;
		if (q.top().r >= len[i])ans++, q.pop();
	}
	printf("%d", ans);
	return 0;
}