记录编号 355259 评测结果 AAAAAAAAAA
题目名称 平凡的题面 最终得分 100
用户昵称 Gravatarsxysxy 是否通过 通过
代码语言 C++ 运行时间 0.131 s
提交时间 2016-11-24 07:16:56 内存使用 2.84 MiB
显示代码纯文本
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cstdarg>
#include <algorithm>
#include <queue>
#include <vector>
#include <cctype>
using namespace std;
//--
char buf[1<<18], *fs, *ft;
inline char readc()
{
    return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<18,stdin),fs==ft))?0:*fs++;
}
inline int fast_read()
{
    int r;
    char c;
    bool sig = false;
    while(c = readc())
    {
        if(c >= '0' && c <= '9')
        {
            r = c^0x30;
            break;
        }else if(c == '-')sig = true;
    }
    while(isdigit(c = readc()))
        r = (r<<3)+(r<<1)+(c^0x30);
    return sig?-r:r;
}
//----------
const int MAXN = 200002;
struct meta
{
    int l, r;
    int type;
    bool operator<(const meta &m)const
    {
        return l < m.l || (l == m.l && type < m.type);
    }
}ms[MAXN];
int main()
{
    freopen("bg.in", "r", stdin);
    freopen("bg.out", "w", stdout);
    int n, m;
    n = fast_read();
    m = fast_read();
    for(int i = 1; i <= n; i++)
    {
        ms[i].l = fast_read();
        ms[i].type = 1;
    }
    for(int i = 1; i <= m; i++)
    {
        ms[i+n].l = fast_read();
        ms[i+n].r = fast_read();
        ms[i+n].type = 0;
    }
    sort(ms+1, ms+1+n+m);
    int ans = 0;
    priority_queue<int, vector<int>, greater<int> >q;
    for(int i =1; i <= n+m; i++)
    {
        if(ms[i].type == 0)
            q.push(ms[i].r);
        else
        {
            int v = ms[i].l;
            while(q.size() && q.top() < v)
                q.pop();
            if(q.size())
            {
                q.pop();
                ans++;
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}