Pagini recente » Cod sursa (job #165193) | Cod sursa (job #2324526) | Cod sursa (job #1833667) | Cod sursa (job #3132071) | Cod sursa (job #1758834)
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream cin("hvrays.in");
ofstream cout("hvrays.out");
const int MAXN = 100000;
struct Point {
int x;
int y;
bool operator < (const Point &other) const {
if (x == other.x)
return y < other.y;
return x < other.x;
}
};
Point horizontal[1 + MAXN], vertical[1 + MAXN];
int main() {
int tests;
cin >> tests;
for (int test = 1; test <= tests; test++) {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> horizontal[i].x >> horizontal[i].y;
for (int i = 1; i <= m; i++)
cin >> vertical[i].x >> vertical[i].y;
sort(horizontal + 1, horizontal + n + 1);
sort(vertical + 1, vertical + m + 1);
int answer = 0, limit = -1;
int i = n, j = m;
while (i) {
if (horizontal[i].y > limit) {
answer++;
while (j && vertical[j].x >= horizontal[i].x) {
limit = max(limit, vertical[j].y);
j--;
}
}
i--;
}
cout << answer << "\n";
}
return 0;
}