Pagini recente » Cod sursa (job #2403931) | Cod sursa (job #2298779) | Cod sursa (job #815723) | Cod sursa (job #2666948) | Cod sursa (job #2091930)
#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,lp,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);
v[0].b = -1;
sol = 0; lp = 0; ilp = 0; last_point = {0,0};
for (int i = 1; i <= n; i ++) {
if (o[i].b > v[ilp].b) {
sol ++;
while (lp <= m && o[i].a <= v[lp].a) {
lp ++;
if (v[ilp].b < v[lp].b) {
ilp = lp;
}
}
}
}
out << sol-1<<"\n";
}
return 0;
}