Pagini recente » Cod sursa (job #740813) | Cod sursa (job #2210883) | Cod sursa (job #2821318) | Cod sursa (job #2623635) | Cod sursa (job #1603937)
#include <fstream>
#define mod 131071
using namespace std;
ifstream fin("ograzi.in");
ofstream fout("ograzi.out");
struct punct
{
long x;
long y;
}c[50010], p, q;
long n, m, w, h, i, j, k, poz, sol, p1, p2;
long hs[mod+40][10], l[mod+40];
void hash(long x, long y)
{
long p1, p2, sol;
p1=x/w;
p2=y/h;
if(x%w==0) p1--;
if(y%h==0) p2--;
// printf("%d %d\n", p1, p2);
sol=(p1*103+p2)%mod;
hs[sol][++l[sol]]=i;
}
int main()
{
fin>>n>>m>>w>>h;
for(i=1; i<=n; i++)
{
fin>>c[i].x>>c[i].y;
c[i].x++;
c[i].y++;
hash(c[i].x, c[i].y);
hash(c[i].x+w, c[i].y);
hash(c[i].x, c[i].y+h);
hash(c[i].x+w, c[i].y+h);
}
for(i=1; i<=m; i++)
{
fin>>p.x>>p.y;
p.x++;
p.y++;
p1=(p.x)/w;
p2=(p.y)/h;
if((p.x)%w==0) p1--;
if((p.y)%h==0) p2--;
poz=(p1*103+p2)%mod;
for(j=1; j<=l[poz]; j++)
{
q=c[hs[poz][j]];
if(q.x<=p.x && p.x<=q.x+w && q.y<=p.y && p.y<=q.y+h)
{
sol++;
break;
}
}
}
fout<<sol;
return 0;
}