Pagini recente » Cod sursa (job #2538913) | Statistici Ciotei Cristian (cristiciotei) | Cod sursa (job #992811) | Cod sursa (job #901155) | Cod sursa (job #2230611)
#include <bits/stdc++.h>
using namespace std;
class InParser {
private:
FILE *fin;
char *buff;
int sp;
char read_ch() {
++sp;
if (sp == 4096) {
sp = 0;
fread(buff, 1, 4096, fin);
}
return buff[sp];
}
public:
InParser(const char* nume) {
fin = fopen(nume, "r");
buff = new char[4096]();
sp = 4095;
}
InParser& operator >> (int &n) {
char c;
while (!isdigit(c = read_ch()) && c != '-');
int sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
InParser& operator >> (long long &n) {
char c;
n = 0;
while (!isdigit(c = read_ch()) && c != '-');
long long sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
};
const int p = 1e6 + 3;
const int MOD = 666013;
int n, m, w, h;
vector <pair <int, int> > v[MOD + 5];
inline bool find(int i, int j, int x, int y){
int List = (1LL * i * p + j) % MOD;
for(auto it : v[List])
if(it.first <= x && it.second <= y && it.first + w >= x && it.second + h >= y) return 1;
return 0;
}
int main()
{
InParser fin("ograzi.in");
freopen("ograzi.out", "w", stdout);
fin >> n >> m >> w >> h;
int x, y;
for(int i = 1; i <= n ; ++i){
fin >> x >> y;
int xg = x / (w + 1), yg = y / (h + 1);
v[(1LL * xg * p + yg) % MOD].push_back({x, y});
}
int Sol = 0;
for(int i = 1; i <= m ; ++i){
fin >> x >> y;
int xg = x / (w + 1), yg = y / (h + 1);
bool ok = 0;
for(int i = max(0, xg - 1); i <= xg && !ok; ++i)
for(int j = max(0, yg - 1); j <= yg && !ok; ++j)
if(find(i, j, x, y)) ok = 1;
Sol += ok;
}
printf("%d", Sol);
return 0;
}