Pagini recente » Cod sursa (job #259575) | Cod sursa (job #885370) | Cod sursa (job #2831393) | Cod sursa (job #530213) | Cod sursa (job #2448258)
#include <fstream>
#include <vector>
using namespace std;
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);
}
}
};
InputReader fin("ograzi.in");
ofstream fout("ograzi.out");
const int MOD = 666013;
int N, M, W, H, sol;
vector < pair <int, int> > Hash[MOD];
int dx[] = {0, -1, 0, -1};
int dy[] = {0, 0, -1, -1};
int Solve(int x, int y)
{
for(int i = 0; i < 4; i++)
{
int key = ((x / W + dx[i]) * 1000 + y / H + dy[i]) % MOD;
if(key < 0)
continue;
for(auto it : Hash[key])
if (it.first <= x && x <= it.first + W && it.second <= y && y <= it.second + H)
return 1;
}
return 0;
}
int main()
{
int x, y;
fin >> N >> M >> W >> H;
for(int i = 1; i <= N; i++)
{
fin >> x >> y;
Hash[((x / W) * 1000 + y / H) % MOD].push_back({x, y});
}
for(int i = 1; i <= M; i++)
{
fin >> x >> y;
sol += Solve(x, y);
}
fout << sol << '\n';
return 0;
}