Pagini recente » Cod sursa (job #815031) | Istoria paginii utilizator/ca.ta.li.na | Cod sursa (job #1008157) | Cod sursa (job #834882) | Cod sursa (job #1776058)
#include <iostream>
#include <cstdio>
#include <unordered_map>
#define MAXN 50050
#define DIM 1000000
using namespace std;
struct coord
{
int x, y;
coord(int x = 0, int y = 0) : x(x), y(y) { }
bool operator==(const coord &e) const{
return e.x == this->x && e.y == this->y;
}
};
struct pair_hash {
inline std::size_t operator()(const coord &v) const {
return v.x*1013+v.y;
}
};
int n, m, w, h, sol, cx, cy, cursor;
unordered_map<coord, coord, pair_hash> has = unordered_map<coord, coord, pair_hash>();
coord oi[2*MAXN];
char buf[DIM];
void adv()
{
cursor++;
if (cursor == DIM)
{
cursor = 0;
fread(buf, 1, DIM, stdin);
}
}
int getInt()
{
while (!(buf[cursor] >= '0' && buf[cursor] <= '9'))
adv();
int nr = 0;
while (buf[cursor] >= '0' && buf[cursor] <= '9')
{
nr = nr*10 + buf[cursor] - '0';
adv();
}
return nr;
}
int cont(int x, int y)
{
auto it = has.find(coord(x, y));
if (it == has.end()) return 0;
coord dr = it->second;
return (dr.x <= cx && dr.x + w >= cx && dr.y <= cy && dr.y + h >= cy);
}
void read()
{
n = getInt();
m = getInt();
w = getInt();
h = getInt();
for (int i = 1; i <= n; i++) {
int x, y;
x = getInt();
y = getInt();
has[coord((x+w-1)/w, (y+h-1)/h)] = coord(x, y);
}
for (int i = 1; i <= m; i++) {
int x, y;
x = getInt();
y = getInt();
cx = x, cy = y;
int rx = (x+w-1)/w, ry = (y+h-1)/h;
sol += cont(rx, ry) || cont(rx-1, ry) || cont(rx, ry-1) || cont(rx-1, ry-1);
}
}
int main()
{
freopen("ograzi.in", "r", stdin);
freopen("ograzi.out", "w", stdout);
fread(buf, 1, DIM, stdin);
read();
printf("%d", sol);
return 0;
}