Cod sursa(job #2709587)

Utilizator marcumihaiMarcu Mihai marcumihai Data 20 februarie 2021 14:45:17
Problema Ograzi Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1 kb
#include <bits/stdc++.h>
#define mod 100003
using namespace std;

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

vector <pair<int,int> > v[100005];
int n,m,w,h;
int rasp;
void cauta (int loc, int x, int y)
{
    if(loc<0)
        return;
    for(int i=0; i<v[loc].size(); ++i)
    {
        if(v[loc][i].first<=x && x<=v[loc][i].first+w && v[loc][i].second<=y && y<=v[loc][i].second+h )
        {
            ++rasp;
        }
    }



}
int main()
{
    f>>n>>m>>w>>h;
    for(int i=1; i<=n; ++i)
    {
        int x, y;
        f>>x>>y;
        int x1=(x+h-1)/w;
        int y1=(y+w-1)/h;
        v[(x1*100+y1)%mod].push_back({x,y});
    }
    for(int i=1; i<=m; ++i)
    {
        int x,y;
        f>>x>>y;
        int x1=(x+h-1)/w;
        int y1=(y+w-1)/h;
        cauta((x1*100+y1)%mod, x, y);
        cauta((x1*100+y1-1)%mod, x, y);
        cauta(((x1-1)*100+y1)%mod, x,y);
        cauta(((x1-1)*100+y1-1)%mod, x, y );

    }
    g<<rasp;
    return 0;
}