Cod sursa(job #2954484)

Utilizator IvanAndreiIvan Andrei IvanAndrei Data 14 decembrie 2022 16:58:57
Problema Ograzi Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.82 kb
#include <fstream>
#include <vector>

using namespace std;

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

const int max_size = 5e4 + 1, mod = 666013, baza = 69;

struct str{
    int xs, ys, xj, yj;
};

str a[max_size];
vector <pair <int, int>> hashuri[mod];

int main ()
{
    int n, m, w, h;
    in >> n >> m >> w >> h;
    for (int i = 1; i <= n; i++)
    {
        in >> a[i].xs >> a[i].yj;
        a[i].xj = a[i].xs + w;
        a[i].ys = a[i].yj + h;
    }
    while (m--)
    {
        int x, y;
        in >> x >> y;
        hashuri[((x / w) * baza + y / h) % mod].push_back({x, y});
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        int dr = ((a[i].xs / w) * baza + a[i].ys / h) % mod;
        for (auto f : hashuri[dr])
        {
            if (a[i].xs <= f.first && f.first <= a[i].xj && a[i].yj <= f.second && f.second <= a[i].ys)
            {
                ans++;
            }
        }
        dr = ((a[i].xs / w) * baza + a[i].yj / h) % mod;
        for (auto f : hashuri[dr])
        {
            if (a[i].xs <= f.first && f.first <= a[i].xj && a[i].yj <= f.second && f.second <= a[i].ys)
            {
                ans++;
            }
        }
        dr = ((a[i].xj / w) * baza + a[i].ys / h) % mod;
        for (auto f : hashuri[dr])
        {
            if (a[i].xs <= f.first && f.first <= a[i].xj && a[i].yj <= f.second && f.second <= a[i].ys)
            {
                ans++;
            }
        }
        dr = ((a[i].xj / w) * baza + a[i].yj / h) % mod;
        for (auto f : hashuri[dr])
        {
            if (a[i].xs <= f.first && f.first <= a[i].xj && a[i].yj <= f.second && f.second <= a[i].ys)
            {
                ans++;
            }
        }
    }
    out << ans;
    in.close();
    out.close();
}