Pagini recente » Cod sursa (job #1890400) | Cod sursa (job #2928075) | Cod sursa (job #712180) | Cod sursa (job #1441019) | Cod sursa (job #1806345)
#include <bits/stdc++.h>
#define MOD 666013
using namespace std;
int dx[]={0,-1,0,-1};
int dy[]={0,0,-1,-1};
int h,w,n,i,j,m,x,y,sol;
vector<pair<int,int> >Hash[MOD];
class InputReader
{
public:
InputReader() {}
InputReader(const char *file_name)
{
input_file=fopen(file_name,"r");
cursor=0,
fread(buffer,SIZE,1,input_file);
}
inline InputReader &operator >>(int &n)
{
while(buffer[cursor]<'0' || buffer[cursor]>'9')
advance();
n=0;
while('0'<=buffer[cursor] && buffer[cursor]<='9')
n=n*10+buffer[cursor]-'0',
advance();
return *this;
}
private:
FILE *input_file;
static const int SIZE = 1<<17;
int cursor;
char buffer[SIZE];
inline void advance()
{
++ cursor;
if(cursor==SIZE)
{
cursor=0;
fread(buffer,SIZE,1,input_file);
}
}
};
bool hash_find(pair<int,int> x)
{
for(int i=0;i<4;i++)
{
int key=((x.first/w+dx[i])*1000+x.second/h+dy[i])%MOD;
if(key<0)
continue;
for(vector<pair<int,int> >::iterator it=Hash[key].begin();it!=Hash[key].end();it++)
if (it->first<=x.first && x.first<=it->first+w && it->second<=x.second && x.second<=it->second+h)
return true;
}
return false;
}
int main()
{
InputReader f("ograzi.in");
freopen("ograzi.out","w",stdout);
f>>n>>m>>w>>h;
for(i=1;i<=n;i++)
f>>x>>y,
Hash[((x/w)*1000+y/h)%MOD].push_back(make_pair(x,y));
for(i=1;i<=m;i++)
f>>x>>y,
sol+=hash_find(make_pair(x,y));
printf("%d",sol);
return 0;
}