Cod sursa(job #2668038)

Utilizator PatrickCplusplusPatrick Kristian Ondreovici PatrickCplusplus Data 4 noiembrie 2020 13:06:18
Problema Ograzi Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("ograzi.in");
ofstream fout("ograzi.out");

const int sigma = 997, mod = 100003;
int n, m, w, h;
vector <pair <int, int> > H[mod + 5];

bool Find(int x, int y, pair <int, int> p){
    if (x < 0 || y < 0) return false;
    int val = (x * sigma + y) % mod;
    for (auto it : H[val]){
        if (p.first <= it.first + w && p.first >= it.first && p.second <= it.second + h && p.second >= it.second){
            return true;
        }
    }
    return false;
}

int main(){
    fin >> n >> m >> w >> h;
    for (int i = 1; i <= n; ++i){
        int x, y;
        fin >> x >> y;
        int val = (x / w * sigma + y / h) % mod;
        H[val].push_back({x, y});
    }
    int contor = 0;
    for (int i = 1; i <= m; ++i){
        int x, y;
        fin >> x >> y;
        pair <int, int> aux = {x, y};
        x /= w;
        y /= h;
        if (Find(x, y, aux) || Find(x - 1, y, aux) || Find(x, y - 1, aux) || Find(x - 1, y - 1, aux)){
            ++contor;
        }
    }
    fout << contor << "\n";
    fin.close();
    fout.close();
    return 0;
}