Cod sursa(job #1599247)

Utilizator AeroHHorea Stefan AeroH Data 13 februarie 2016 18:47:54
Problema Ograzi Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.23 kb
#include <tr1/unordered_map>
#include <fstream>
#define x first
#define y second
#define ha 10000000
using namespace std;
using namespace tr1;
string z="ograzi.";
ifstream f(z+"in");
ofstream g(z+"out");

int i,n,t,h,w,x,y,rasp,x1,y1;
unordered_map<long long int,int> m;
//int m[10];
pair<int,int> v[50001],a;

void check(int x,int y)
{
    a=v[m[x/w*ha+y/h]];
    if (a.x <= x && x <= a.x+w && a.y <= y && y <= a.y+h)
        {
            ++rasp;
            return ;
        }
    a=v[m[1ll*(-1+x/w)*ha+y/h]];
    if (a.x <= x && x <= a.x+w && a.y <= y && y <= a.y+h)
        {
            ++rasp;
            return ;
        }
    a=v[m[1ll*x/w*ha+y/h-1]];
    if (a.x <= x && x <= a.x+w && a.y <= y && y <= a.y+h)
        {
            ++rasp;
            return ;
        }
    a=v[m[1ll*(-1+x/w)*ha+y/h-1]];
    if (a.x <= x && x <= a.x+w && a.y <= y && y <= a.y+h)
        {
            ++rasp;
            return ;
        }
}

int main()
{
    f>>n>>t>>w>>h;
    for (i=1;i<=n;++i)
    {
        f>>x>>y;
        v[i]={x,y};
        x/=w;
        y/=h;
        m[1ll*x*ha+y]=i;
    }
    for(i=1;i<=t;++i)
    {
        f>>x>>y;
        check(x,y);
    }
    g<<rasp;
    return 0;
}