Pagini recente » Cod sursa (job #2487338) | Cod sursa (job #2657895) | Cod sursa (job #2379387) | Cod sursa (job #2241862) | Cod sursa (job #1758835)
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
class InputReader {
public:
InputReader() {}
InputReader(const char *file_name) {
input_file = fopen(file_name, "r");
cursor = 0;
fread(buffer, SIZE, 1, input_file);
}
inline InputReader &operator >>(int &n) {
while(buffer[cursor] < '0' || buffer[cursor] > '9') {
advance();
}
n = 0;
while('0' <= buffer[cursor] && buffer[cursor] <= '9') {
n = n * 10 + buffer[cursor] - '0';
advance();
}
return *this;
}
private:
FILE *input_file;
static const int SIZE = 1 << 17;
int cursor;
char buffer[SIZE];
inline void advance() {
++ cursor;
if(cursor == SIZE) {
cursor = 0;
fread(buffer, SIZE, 1, input_file);
}
}
};
InputReader 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;
}