Cod sursa(job #2230608)

Utilizator giotoPopescu Ioan gioto Data 10 august 2018 18:56:45
Problema Ograzi Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.06 kb
#include <bits/stdc++.h>
using namespace std;

const int p = 1e5 + 3;
const int MOD = 666013;
int n, m, w, h;
vector <pair <int, int> > v[MOD + 2];
inline bool find(int i, int j, int x, int y){
    int List = (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()
{
    freopen("ograzi.in", "r", stdin);
    freopen("ograzi.out", "w", stdout);

    scanf("%d%d%d%d", &n, &m, &w, &h);
    int x, y;
    for(int i = 1; i <= n ; ++i){
        scanf("%d%d", &x, &y);
        int xg = x / (w + 1), yg = y / (h + 1);
        v[(xg * p + yg) % MOD].push_back({x, y});
    }

    int Sol = 0;
    for(int i = 1; i <= m ; ++i){
        scanf("%d%d", &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;
}