Cod sursa(job #2639070)

Utilizator stefantagaTaga Stefan stefantaga Data 31 iulie 2020 11:31:59
Problema Ograzi Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <bits/stdc++.h>
#define MOD 100003
using namespace std;
ifstream f("ograzi.in");
ofstream g("ograzi.out");
int n,m,w,h,x,y,x2,y2,nr;
vector <pair <int,int> > v[100005];
void verif (int loc,pair <int,int> punct)
{
    for (int j=0;j<v[loc].size();j++)
    {
        if (v[loc][j].first<=punct.first&&punct.first<=v[loc][j].first+w&&v[loc][j].second<=punct.second&&punct.second<=v[loc][j].second+h)
        {
            nr++;
        }
    }
}
int i;
int main()
{
    f>> n >> m >> w >> h;
    for (i=1;i<=n;i++)
    {
        f>>x>>y;
        x2=(x+w-1)/w;
        y2=(y+h-1)/h;
        v[(x2*100+y2)%MOD].push_back({x,y});
    }
    for (i=1;i<=m;i++)
    {
        f>>x>>y;
        x2=(x+w-1)/w;
        y2=(y+h-1)/h;
        verif((x2*100+y2)%MOD,{x,y});
        verif(((x2-1)*100+y2)%MOD,{x,y});
        verif(((x2-1)*100+y2-1)%MOD,{x,y});
        verif((x2*100+y2-1)%MOD,{x,y});
    }
    g<<nr;
    return 0;
}