Pagini recente » Cod sursa (job #1652148) | Cod sursa (job #1401681) | Cod sursa (job #2363030) | Cod sursa (job #196842) | Cod sursa (job #1895757)
#include <bits/stdc++.h>
using namespace std;
ofstream fout("ograzi.out");
const int nmax = 100005;
const int X = 13;
const int Y = 37;
const int mod = 123457;
int N,M,W,H,ans;
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);
}
}
};
struct el
{
int x,y;
};
vector < el > h[mod+5];
inline void Insert(int a, int b, el w)
{
int p;
p = (a*X + b*Y)%mod;
h[p].push_back(w);
}
inline int Find(int a, int b, int x, int y)
{
int p;
p = (a*X + b*Y)%mod;
for(auto it : h[p])
{
if(it.x <= x && it.x + W >= x && it.y <= y && y <= it.y + H) return 1;
}
return 0;
}
inline void Solve()
{
InputReader fin("ograzi.in");
int i,x,y,a,b;
el w;
fin >> N >> M >> W >> H;
for(i = 1; i <= N; i++)
{
fin >> w.x >> w.y;
w.x++; w.y++;
a = w.x / W;
b = w.y / H;
Insert(a,b,w);
//cout << a << " " << b << "\n";
}
for(i = 1; i <= M; i++)
{
fin >> x >> y;
x++;y++;
a = x / W;
b = y / H;
ans += (Find(a,b,x,y)| Find(a,b-1,x,y) | Find(a-1,b,x,y) | Find(a-1,b-1,x,y));
}
fout << ans << "\n";
}
int main()
{
Solve();
fout.close();
return 0;
}