Pagini recente » Cod sursa (job #1718846) | Cod sursa (job #52149) | Cod sursa (job #1192689) | Cod sursa (job #1630857) | Cod sursa (job #2338360)
#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
const ll INF = 9223372036854775807ll;
const int inf = 2147483647;
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;
}
};
int n, m, h, w, t;
unordered_map<ll, pi> mp;
pi v[50005];
ll hsh(pi x)
{
return 10000000ll*(x.ff-(x.ff%h)) + (x.ss-(x.ss%w));
}
pi close(pi x)
{
x.ff -= x.ff%h;
x.ss -= x.ss%w;
return x;
}
bool inside(pi drp, pi x)
{
return x.ff >= drp.ff && x.ff <= drp.ff+h && x.ss >= drp.ss && x.ss <= drp.ss+w;
}
int main()
{
InParser fin ("ograzi.in");
ofstream fout ("ograzi.out");
fin >> n >> m >> w >> h;
for (int i = 1; i <= n; ++i){
fin >> v[i].ff >> v[i].ss;
mp[hsh(v[i])] = v[i];
}
int ans = 0;
for (int i = 1; i <= m; ++i){
pi now;
fin >> now.ff >> now.ss;
if(mp.find(hsh(now)) != mp.end()){
if(inside(mp[hsh(now)], now)){
++ans;
continue;
}
}
pi now2 = close(now);
now2.ff -= h;
if(mp.find(hsh(now2)) != mp.end()){
if(inside(mp[hsh(now2)], now)){
++ans;
continue;
}
}
now2 = close(now);
now2.ss -= w;
if(mp.find(hsh(now2)) != mp.end()){
if(inside(mp[hsh(now2)], now)){
++ans;
continue;
}
}
now2 = close(now);
now2.ff -= h;
now2.ss -= w;
if(mp.find(hsh(now2)) != mp.end()){
if(inside(mp[hsh(now2)], now)){
++ans;
continue;
}
}
}
fout << ans << "\n";
return 0;
}