Pagini recente » Cod sursa (job #2292929) | Cod sursa (job #3243787) | Cod sursa (job #2938395) | Cod sursa (job #301205) | Cod sursa (job #2090998)
#include<fstream>
#include<algorithm>
using namespace std;
class InParser {
private:
FILE *fin;
char *buff;
int sp;
char read_ch() {
++sp;
if (sp == 4096) {
sp = 0;
fread(buff, 1, 4096, fin);
}
return buff[sp];
}
public:
InParser(const char* nume) {
fin = fopen(nume, "r");
buff = new char[4096]();
sp = 4095;
}
InParser& operator >> (int &n) {
char c;
while (!isdigit(c = read_ch()) && c != '-');
int sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
InParser& operator >> (long long &n) {
char c;
n = 0;
while (!isdigit(c = read_ch()) && c != '-');
long long sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
} in( "hvrays.in" );
ofstream out ("hvrays.out");
int n,m,t,ilp,sol;
struct punct {
int a,b;
}o[100001],v[10001],last_point;
bool cmp (punct x, punct y) {
if (x.a == y.a) {
return x.b < y.b;
}
return x.a < y.a;
}
int main (void) {
in >> t;
for (int h = 1; h <= t; h ++) {
in >> n >> m;
for (int i = 1; i <= n; i ++) {
in >> o[i].a >> o[i].b;
}
for (int i = 1; i <= m; i ++) {
in >> v[i].a >> v[i].b;
}
sort (v + 1, v + m + 1,cmp);
sort (o + 1, o + n + 1,cmp);
sol = 0; ilp = 0; last_point = {0,0};
for (int i = 1; i <= m; i ++) {
if ( (i > 1) && (v[i].a <= last_point.a || v[i].b <= last_point.b)) {
continue;
}
sol ++;
while (true) {
if (o[ilp].a > v[i].a || o[ilp].b > v[i].b || ilp > n) {
break;
}
last_point = o[ilp];
ilp ++;
}
}
out << sol<<"\n";
}
return 0;
}