Pagini recente » Profil ceorno | Cod sursa (job #927602) | Cod sursa (job #1845088) | Cod sursa (job #2087522) | Cod sursa (job #1398468)
#include <fstream>
#include <set>
#include <algorithm>
#include <vector>
using namespace std;
ifstream f("ograzi.in");
ofstream g("ograzi.out");
int N,M,W,H;
multiset <int> S;
const int NMax = 50005;
const int MMax = 100005;
const int P = 100003;
const int MOD = 100000;
vector < pair<int,int> > Hash[MMax];
int dx[]={0,0,-1,-1};
int dy[]={0,-1,0,-1};
void Insert(pair <int,int> Point)
{
int List=(1LL*(Point.first/W)*P+Point.second/H)%MOD;
Hash[List].push_back(Point);
}
bool Find(pair <int,int> Point)
{
int List=(1LL*Point.first*P+Point.second)%MOD;
for(int i=0;i<Hash[List].size();i++)
if(Hash[List][i]==Point)
return 1;
return 0;
}
inline bool Inside(pair <int,int> pointX,pair <int,int> pointY)
{
return pointX.first<=pointY.first && pointX.first+W>=pointY.first && pointX.second<=pointY.second && pointX.second+H>=pointY.second;
}
void Process()
{
f>>N>>M>>W>>H;
pair <int,int> Point;
for(int i=1;i<=N;i++)
{
f>>Point.first>>Point.second;
Insert(Point);
}
int result=0;
for(int i=1;i<=M;i++)
{
f>>Point.first>>Point.second;
bool ok=0;
for(int j=0;j<4;j++)
{
int List=(1LL*(Point.first/W+dx[j])*P+(Point.second/H+dy[j]))%MOD;
if(Point.first+dx[j]<0 || Point.second+dy[j]<0)
continue;
for(int k=0;k<Hash[List].size();k++)
{
if(Inside(Hash[List][k],Point)==1)
{
++result;
ok=1;
break;
}
}
if(ok==1)
break;
}
}
g<<result<<"\n";
}
int main()
{
Process();
return 0;
}