Cod sursa(job #1065843)

Utilizator misinozzz zzz misino Data 23 decembrie 2013 19:01:31
Problema Hvrays Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.41 kb
#include<fstream>
#include<algorithm>
#define x first
#define y second
#define N 100010
#define D 1000000
#define punct pair<int,int>
using namespace std;
int t,i,sol,h,v,p,poz=D+3,cur,maxi;
punct vh[N],vv[N];
char buf[D];
inline int ianr()
{
    unsigned int nr=0;
    while((buf[poz]<'0'||buf[poz]>'9')&&buf[poz]!='-')
    if(++poz>=D)
    fread(buf,D,1,stdin),poz=0;
    int semn=1;
    if(buf[poz]=='-')
    ++poz,semn=-1;
    while('0'<=buf[poz]&&buf[poz]<='9')
    {
        nr=nr*10+buf[poz]-'0';
        if(++poz>=D)
        fread(buf,D,1,stdin),poz=0;
    }
    return nr*semn;
}
inline bool cmp(punct a,punct b)
{
    return a.y>b.y;
}
int main()
{
    freopen("hvrays.in","r",stdin);
    freopen("hvrays.out","w",stdout);
    t=ianr();
    for(;t;--t)
    {
        h=ianr();
        v=ianr();
        for(i=1;i<=h;++i)
        vh[i].x=ianr(),vh[i].y=ianr();
        for(i=1;i<=v;++i)
        vv[i].x=ianr(),vv[i].y=ianr();
        sort(vh+1,vh+h+1,cmp);
        sort(vv+1,vv+v+1,cmp);
        p=1;
        cur=maxi=-1;
        sol=0;
        for(i=1;i<=h;++i)
        {
            while(p<=v&&vv[p].y>=vh[i].y)
            {
                maxi=max(maxi,vv[p].x);
                ++p;
            }
            if(cur<maxi)
            {
                cur=maxi;
                ++sol;
            }
        }
        printf("%d\n",sol);
    }
    return 0;
}