Pagini recente » Cod sursa (job #1418709) | Cod sursa (job #1838048) | Cod sursa (job #2511419) | Cod sursa (job #1735672) | Cod sursa (job #27277)
Cod sursa(job #27277)
#include <stdio.h>
#include <vector>
using namespace std;
#define LL unsigned int
#define ff first
#define ss second
#define NRB 15
LL NR1;
int N, M, W, H, jeg;
int nr1[1 << 18];
pair <int, int> hash1[1 << 18][6];
inline int srch(int x, int y, int md1)
{
int i;
for (i = 0; i < nr1[md1]; i++)
if (x - W <= hash1[md1][i].ff && hash1[md1][i].ff <= x && y - H <= hash1[md1][i].ss && hash1[md1][i].ss <= y) return 1;
return 0;
}
inline LL trans(int x, int y) { return x / W + (LL) y / H * jeg; }
inline LL trans1(int x, int y) { return x + (LL) y * jeg; }
int main()
{
int i, x, y;
int md1;
freopen("ograzi.in", "r", stdin);
freopen("ograzi.out", "w", stdout);
scanf("%d %d %d %d", &N, &M, &W, &H);
NR1 = (LL) 1231513223 * 151231;
LL aux;
jeg = 1000000 / W;
for (i = 1; i <= N; i++) {
scanf("%d %d", &x, &y);
aux = trans(x, y);
md1 = (aux * NR1) >> NRB;
hash1[md1][nr1[md1]++] = make_pair(x, y);
}
int ww, hh, rez = 0;
for (i = 1; i <= M; i++) {
scanf("%d %d", &x, &y);
ww = x / W; hh = y / H;
md1 = (trans1(ww, hh) * NR1) >> NRB;
if (srch(x, y, md1)) { rez++; continue; }
md1 = (trans1(ww-1, hh) * NR1) >> NRB;
if (srch(x, y, md1)) { rez++; continue; }
md1 = (trans1(ww, hh-1) * NR1) >> NRB;
if (srch(x, y, md1)) { rez++; continue; }
md1 = (trans1(ww-1, hh-1) * NR1) >> NRB;
if (srch(x, y, md1)) { rez++; continue; }
}
printf("%d\n", rez);
fclose(stdin);
fclose(stdout);
return 0;
}