Pagini recente » Cod sursa (job #1328513) | Cod sursa (job #1648481) | Cod sursa (job #2817831) | Cod sursa (job #1715460) | Cod sursa (job #1734129)
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <functional>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <iomanip>
#define NMAX 200006
#define INF 0x3f3f3f3f
#define pb push_back
#define MOD 30013
using namespace std;
typedef pair<int, int> pii;
//ifstream fin("ograzi.in");
ofstream fout("ograzi.out");
vector<pii> Hash[MOD];
int h,w;
int dlin[4]={0,0,-1,-1};
int dcol[4]={0,-1,-1,0};
inline int hashval(int x, int y) {
return (x*1000+y)%MOD;
}
inline bool find_hash(pii p) {
int i,where;
for(i=0;i<4;++i) {
where=hashval(p.first/w+dlin[i],p.second/h+dcol[i]);
if(where<0) continue;
for(auto it:Hash[where])
if(it.first<=p.first && p.first<=it.first+w && it.second<=p.second && p.second<=it.second+h) return 1;
}
return 0;
}
FILE* fin=fopen("ograzi.in","r");
const unsigned maxb=30000192;
char buf[maxb];
unsigned ptr=maxb;
inline void read(int &nr){
nr=0;
while(buf[ptr]<'0'||'9'<buf[ptr])
if(++ptr>=maxb)
fread(buf,maxb,1,fin),ptr=0;
while('0'<=buf[ptr]&&buf[ptr]<='9'){
nr=nr*10+buf[ptr]-'0';
if(++ptr>=maxb)
fread(buf,maxb,1,fin),ptr=0;
}
}
int main() {
int n,m,i,x,y,nr=0;
read(n); read(m); read(w); read(h);
for(i=0;i<n;++i) {
read(x); read(y);
Hash[hashval(x/w,y/h)].pb({x,y});
}
for(i=0;i<m;++i) {
read(x); read(y);
if(find_hash({x,y})) ++nr;
}
fout<<nr;
return 0;
}