Cod sursa(job #1603937)

Utilizator andreiudilaUdila Andrei andreiudila Data 17 februarie 2016 20:43:43
Problema Ograzi Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.25 kb
#include <fstream>

#define mod 131071

using namespace std;



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


struct punct
{
    long x;
    long y;
}c[50010], p, q;


long n, m, w, h, i, j, k, poz, sol, p1, p2;
long hs[mod+40][10], l[mod+40];


void hash(long x, long y)
{
    long p1, p2, sol;
    p1=x/w;
    p2=y/h;
    if(x%w==0) p1--;
    if(y%h==0) p2--;
//   printf("%d %d\n", p1, p2);
    sol=(p1*103+p2)%mod;
    hs[sol][++l[sol]]=i;
}

int main()
{


    fin>>n>>m>>w>>h;

    for(i=1; i<=n; i++)
    {
        fin>>c[i].x>>c[i].y;

        c[i].x++;
        c[i].y++;

        hash(c[i].x, c[i].y);
        hash(c[i].x+w, c[i].y);
        hash(c[i].x, c[i].y+h);
        hash(c[i].x+w, c[i].y+h);
    }

    for(i=1; i<=m; i++)
    {


        fin>>p.x>>p.y;

        p.x++;
        p.y++;
        p1=(p.x)/w;
        p2=(p.y)/h;
        if((p.x)%w==0) p1--;
        if((p.y)%h==0) p2--;
        poz=(p1*103+p2)%mod;

        for(j=1; j<=l[poz]; j++)
        {
            q=c[hs[poz][j]];
            if(q.x<=p.x && p.x<=q.x+w && q.y<=p.y && p.y<=q.y+h)
            {
                sol++;
                break;
            }
        }
    }
    fout<<sol;
    return 0;
}