Pagini recente » Cod sursa (job #2852129) | Cod sursa (job #3174214) | Cod sursa (job #744971) | Cod sursa (job #2224302) | Cod sursa (job #1065840)
#include<fstream>
#include<algorithm>
#define x first
#define y second
#define N 100010
#define D 1000000
#define punct pair<int,int>
using namespace std;
ifstream f("hvrays.in");
ofstream g("hvrays.out");
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()
{
f>>t;
for(;t;--t)
{
f>>h>>v;
for(i=1;i<=h;++i)
f>>vh[i].x>>vh[i].y;
for(i=1;i<=v;++i)
f>>vv[i].x>>vv[i].y;
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;
}
}
g<<sol<<'\n';
}
return 0;
}