Pagini recente » Cod sursa (job #1686407) | Cod sursa (job #2506159) | Cod sursa (job #473022) | Cod sursa (job #2473211) | Cod sursa (job #2273718)
#include <bits/stdc++.h>
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("ograzi.in");
ofstream out("ograzi.out");
const int CNS = 3541541;
const int MOD = 666013;
vector<pair<int, int>> hsh[MOD];
inline int getHash(int x, int y) {
return (1LL * x * CNS + y) % MOD;
}
int _w, _h;
bool verify(int p1, int p2, int x, int y) {
if (p1 < 0 or p2 < 0)
return false;
int pos = getHash(p1, p2);
for (pair<int, int> pr : hsh[pos]) {
if (pr.first <= x and pr.second <= y and
pr.first + _w >= x and pr.second + _h >= y)
return true;
}
return false;
}
int main(void) {
int n, m, w, h;
in >> n >> m >> w >> h; _w = w; _h = h;
for (int i = 1; i <= n; ++i) {
int x, y, p1, p2;
in >> x >> y;
p1 = x / (w + 1); p2 = y / (h + 1);
hsh[getHash(p1, p2)].push_back(make_pair(x, y));
}
int ans = 0;
for (int i = 1; i <= m; ++i) {
int x, y, p1, p2; bool ok = false;
in >> x >> y;
p1 = x / (w + 1); p2 = y / (h + 1);
for (int q1 = p1 - 1; q1 <= p1 and !ok; ++q1)
for (int q2 = p2 - 1; q2 <= p2 and !ok; ++q2)
ok |= verify(q1, q2, x, y);
ans += ok;
}
out << ans << endl;
return 0;
}