Pagini recente » Cod sursa (job #1681292) | Cod sursa (job #2000812) | Cod sursa (job #229895) | Cod sursa (job #270740) | Cod sursa (job #1065843)
#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;
}