记录编号 203647 评测结果 AAAAAAAAAA
题目名称 平凡的题面 最终得分 100
用户昵称 Gravatarpppoooiiizzy 是否通过 通过
代码语言 C++ 运行时间 0.328 s
提交时间 2015-11-03 14:06:03 内存使用 1.46 MiB
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<functional>
#include<queue>
#include<vector>
#include<set>
#include<cstring>
#include<string>
#include<stack>
 
const int maxn = 100000 + 5;
using namespace std;
 
#define rep(i, j, k) for(int i = j; i <= k; i++)
#define drep(i, j, k) for(int i = j; i >= k; i--)
#define INF 0x3fffffff
#define LL long long
 
inline int read()
{
    int x = 0, f = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while(ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}
 
struct point {
    int L, R;
}a[maxn];
 
multiset<int>s;
int m, n, Ar, Sa, cnt, ans, tot, b1, b2;
int vis[maxn];

bool cmp(const point i, const point j) { return i.R < j.R;
}
void init()
{
    n = read(), m = read();
    rep(i, 1, n) {Ar = read(); b1 = min(b1, Ar); s.insert(Ar);}
    rep(i, 1, m) a[i].L = read(), a[i].R = read();
}
 
void print()
{
    rep(i, 1, m) { cout<<a[i].L<<" "<<a[i].R<<endl; }
}
 
int main()
{
	freopen("bg.in", "r", stdin);
    freopen("bg.out", "w", stdout);
    init();
    sort(a + 1, a + 1 + m, cmp);
    multiset<int>::iterator it;
    multiset<int>::iterator itt;
    rep(i, 1, m) {
        it = s.find(a[i].L);
        if(it == s.end()) {
        	it = itt = s.insert(a[i].L);
        	it++;
        	s.erase(itt);
        	if( it != s.end() && *it <= a[i].R) {
        		ans++;
        		s.erase(it);
			}
		}
		else {
			s.erase(it);
			ans++;
		}
    }
    cout<<ans<<endl;
}