Pagini recente » Cod sursa (job #1822906) | Cod sursa (job #1585323) | Cod sursa (job #209247) | Cod sursa (job #1237103) | Cod sursa (job #2134107)
#include <bits/stdc++.h>
using namespace std;
ifstream f("ograzi.in");
ofstream g("ograzi.out");
const int MaxN = 50005;
unordered_map<pair<int, int>, vector<pair<int, int> > > H;
int n, m, w, h, ans, poz;
pair<int, int> v[MaxN];
inline bool verif(int x, int y) {
return x >= v[poz].first && x <= v[poz].first + w &&
y >= v[poz].second && y <= v[poz].second + h;
}
inline void cauta(vector<pair<int, int> > hh) {
int sz = hh.size();
for (int i = 0; i < sz; ++i) {
if (verif(hh[i].first, hh[i].second)) {
++ans;
swap(hh[i], hh[sz - 1]);
hh.pop_back();
--sz;
--i;
}
}
}
int main()
{
f >> n >> m >> w >> h;
for (int i = 1; i <= n; ++i) {
int x, y;
f >> x >> y;
v[i] = {x, y};
}
for (int i = 1; i <= m; ++i) {
int x, y;
f >> x >> y;
H[{x / w, y / h}].push_back({x, y});
}
for (int i = 1; i <= n; ++i) {
int x = v[i].first, y = v[i].second, b1 = x / w, b2 = y / h;
poz = i;
cauta(H[{b1, b2}]);
cauta(H[{b1 + 1, b2}]);
cauta(H[{b1, b2 + 1}]);
cauta(H[{b1 + 1, b2 + 1}]);
}
g << ans << '\n';
return 0;
}