Cod sursa(job #1061075)

Utilizator assa98Andrei Stanciu assa98 Data 19 decembrie 2013 10:17:26
Problema Ograzi Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.21 kb
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

const int MOD=66617;
const int MAX_N=50100;

int h,w;

inline int hash(int x,int y) {
    x/=w;
    y/=h;
    return ((x%MOD)*327 + (y%MOD)*581)%MOD;
}

vector<int> H[MOD + 100];

pair<int,int> v[MAX_N];

bool intersect(int x,int y,int poz) {
    return (x>=v[poz].first && x<=v[poz].first+w) && (y>=v[poz].second && y<=v[poz].second +h);
}

int main() {
    freopen("ograzi.in","r",stdin);
    freopen("ograzi.out","w",stdout);
    
    int n,m;
    scanf("%d%d%d%d",&n,&m,&w,&h);

    for(int i=1;i<=n;i++) {
        scanf("%d%d",&v[i].first,&v[i].second);

        H[ hash( v[i].first , v[i].second) ].push_back(i);
        H[ hash( v[i].first + w , v[i].second) ].push_back(i);
        H[ hash( v[i].first , v[i].second + h) ].push_back(i);
        H[ hash( v[i].first + w , v[i].second + h) ].push_back(i);
    }
    
    int ans=0;
    for(int i=1;i<=m;i++) {
        int x,y;
        scanf("%d%d",&x,&y);
        for(vector<int>::iterator it=H[hash(x,y)].begin(); it!=H[hash(x,y)].end(); it++) {
            if(intersect(x,y,*it)) {
                ans++;
                break;
            }
        }
    }
    
    printf("%d",ans);

    return 0;
}