Pagini recente » Cod sursa (job #1452267) | Cod sursa (job #422578) | Cod sursa (job #1157232) | Cod sursa (job #3142489) | Cod sursa (job #2587660)
#include <bits/stdc++.h>
#define mod 666013
#define c 997
using namespace std;
ofstream fout("ograzi.out");
int n, m, w, h;
struct el
{
int x, y;
};
vector <el> t[mod+6];
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);
}
}
};
inline void Insert(int a, int b,el p)
{
int val = (a*c + b) % mod;
t[val].push_back(p);
}
inline int Find(int a, int b, int x, int y)
{
if (a < 0 || b < 0)
return 0;
int val = (a*c + b) % mod;
for (auto it : t[val])
{
if (it.x <= x && x <= it.x + w && it.y <= y && y <= it.y + h)
return 1;
}
return 0;
}
inline void solve()
{
InputReader fin("ograzi.in");
fin >> n >> m >> w >> h;
for (int i = 1; i <= n; i++)
{
el p;
int a, b;
fin >> a >> b;
p = {a, b};
a++, b++;
Insert(a/w, b/h, p);
}
int ans = 0;
for (int i = 1; i <= m; i++)
{
int x, y;
x++, y++;
fin >> x >> y;
int a, b;
a = x/w;
b = y/h;
ans += (Find(a, b, x, y) | Find(a, b-1, x, y) | Find(a-1, b, x, y) | Find(a-1, b-1, x, y));
}
fout << ans;
}
int main()
{
solve();
return 0;
}