Cod sursa(job #877645)

Utilizator Marius96Marius Gavrilescu Marius96 Data 13 februarie 2013 00:48:26
Problema Ograzi Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.12 kb
#include<cstdio>
#include<tr1/unordered_map>
using std::tr1::unordered_multimap;
using std::pair;
using std::make_pair;

static int x[50005];
static int y[50005];
static int w,h;

struct hash_pair
{
	int operator()(pair<int, int> p)const
		{
			return p.first^p.second;
		}
};

#define MAP unordered_multimap<pair<int,int>, pair<int,int>, hash_pair>
#define IT MAP::iterator
#define inside(s,a,b) a<=s.first && a+w>=s.first && b<=s.second && b+h>=s.second

static MAP hash;

int main (void)
{
	freopen ("ograzi.in","r",stdin);
#ifdef INFOARENA
	freopen ("ograzi.out","w",stdout);
#endif

	int n,m;
	scanf ("%d%d%d%d",&n,&m,&w,&h);

	for(int i=0;i<n;i++)
		scanf ("%d %d",x+i,y+i);

	for(int j=0;j<m;j++){
		int x,y;
		scanf ("%d%d",&x,&y);

		hash.insert (make_pair (make_pair (x/w,y/h), make_pair (x,y)));
	}

	int ans=0;
	for(int i=0;i<n;i++){
		const int sa=x[i]/w;
		const int sb=y[i]/h;
		pair<IT,IT> p;

		for(int a=sa;a<sa+2;a++)
			for(int b=sb;b<sb+2;b++){
				p=hash.equal_range (make_pair (a,b));
				for(IT it=p.first;it!=p.second;it++)
					if(inside (it->second,x[i],y[i]))
						ans++;
			}
	}

	printf ("%d",ans);
	return 0;
}