Pagini recente » Cod sursa (job #2340650) | Cod sursa (job #1771158) | Cod sursa (job #2911135) | Cod sursa (job #1533593) | Cod sursa (job #1020958)
#include <cstdio>
#include <vector>
#include <utility>
using namespace std;
char buff[1<<15];
const int MOD = 66013;
int n,m;
int w,h;
const int dx[] = {1, 0, -1};
const int dy[] = {1, 0, -1};
vector< pair<int, int> > hsh[MOD];
inline int key(const int x, const int y){
return (1LL * x * x * h + y * 3) % MOD;
}
void insert(const int x, const int y){
const int chain = key(x/w, y/h);
hsh[chain].push_back(make_pair(x, y));
}
bool search(const int x, const int y){
for(int i = 0 ; i < 3 ; ++i)for(int j = 0 ; j < 3 ; ++j){
const int new_x = x/w + dx[i],
new_y = y/h + dy[j];
const int chain = key(new_x, new_y);
for(unsigned int i = 0 ; i < hsh[chain].size() ; ++i){
const pair<int, int> now = hsh[chain][i];
if(now.first <= x && x <= now.first + w && now.second <= y && y <= now.second + h)
return 1;
}
}
return 0;
}
int main(){
freopen("ograzi.in", "r", stdin);
freopen("ograzi.out", "w", stdout);
setvbuf(stdin, buff, _IOFBF, sizeof(buff));
scanf("%d%d%d%d", &n, &m, &w, &h);
int x,y;
for(int i = 0 ; i < n ; ++i){
scanf("%d%d", &x, &y);
insert(x, y);
}
int fnd = 0;
for(int i = 0 ; i < m ; ++i){
scanf("%d%d", &x, &y);
if(search(x, y))
++fnd;
}
printf("%d\n", fnd);
}