Pagini recente » Cod sursa (job #1239554) | Cod sursa (job #688712) | Cod sursa (job #2015489) | Cod sursa (job #274840) | Cod sursa (job #1506046)
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define mod 6666013
#define maxN 50002
#define maxM 100002
#define inf 1000002LL
#define ll long long
using namespace std;
struct point
{
int x;
int y;
};
ll val;
int i, j, n, m, w, h, x, y, sol;
vector < point > V[mod];
ll Vall(point a)
{
return (long long)((a.x / w) * inf * 1LL + (a.y / h) * 1LL);
}
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);
}
}
};
int ok(point a, point b)
{
return a.x <= b.x && b.x <= a.x + w && a.y <= b.y && b.y <= a.y + h;
}
int In_hash(ll val, point sheep)
{
ll x = val % mod, a, b;
int i, l = V[x].size();
for (i = 0; i < l; ++ i)
if (Vall(V[x][i]) == val && ok(V[x][i], sheep))
return 1;
return 0;
}
void rs()
{
point orch;
InputReader cin("ograzi.in");
cin >> n >> m >> w >> h;
for (i = 1; i <= n; ++ i)
{
cin >> x >> y;
val = (long long)((x / w) * inf * 1LL + (y / h) * 1LL);
orch.x = x; orch.y = y;
V[val % mod].push_back(orch);
}
int z, t;
point sheep;
while (m --)
{
cin >> x >> y;
sheep.x = x;
sheep.y = y;
for (z = -1; z < 1; ++ z)
for (t = -1; t < 1; ++ t)
{
ll val = (long long)(((x / w) + z) * inf * 1LL + (y / h) * 1LL + t);
if (val >= 0 && In_hash(val, sheep))
{
++ sol;
z = 1;
t = 1;
}
}
}
}
void write()
{
freopen("ograzi.out", "w", stdout);
printf("%d", sol);
}
int main()
{
rs();
write();
return 0;
}