Cod sursa(job #2932103)

Utilizator robertanechita1Roberta Nechita robertanechita1 Data 1 noiembrie 2022 21:39:31
Problema Ograzi Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.22 kb
#include <bits/stdc++.h>

using namespace std;

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

int n, m, w, h;
const int c1 = 43, c2 = 19, mod = 14411;
struct Elem{
    int x, y;
};
vector <Elem> L[15005];

int Find(int a, int b, int x, int y){
    if(a < 0 || b < 0) return 0;
    int poz = (a * c1 + b * c2) % mod;
    for(auto e : L[poz])
        if(x >= e.x && x <= e.x + w && y >= e.y && y <= e.y + h) return 1;
    return 0;
}

void Read(){
    std::ios::sync_with_stdio(false);
    fin.tie (nullptr);
//    InputReader fin("ograzi.in");
    fin >> n >> m >> w >> h;
    Elem e;
    for(int i = 1; i <= n; i++){
        fin >> e.x >> e.y;
        e.x++;
        e.y++;
        int a = e.x / w;
        int b = e.y / h;
        int poz = (a * c1 + b * c2) % mod;
        L[poz].push_back(e);
        ///dreptunghi
    }
    int x, y;
    int sol = 0;
    for(int i = 1; i <= m; i++){
        fin >> x >> y;
        x++;
        y++;
        int a = x / w;
        int b = y / h;
        sol += (Find(a, b, x, y) | Find(a - 1, b, x, y) | Find(a, b - 1, x, y) | Find(a - 1, b - 1, x, y));
    }
    fout << sol << "\n";
    fout.close();
}

int main()
{
    Read();
    return 0;
}