Cod sursa(job #2639071)

Utilizator stefantagaTaga Stefan stefantaga Data 31 iulie 2020 11:33:14
Problema Ograzi Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.84 kb
#include <bits/stdc++.h>
#define MOD 100003
using namespace std;
ofstream g("ograzi.out");
class InParser {
private:
	FILE *fin;
	char *buff;
	int sp;

	char read_ch() {
		++sp;
		if (sp == 4096) {
			sp = 0;
			fread(buff, 1, 4096, fin);
		}
		return buff[sp];
	}

public:
	InParser(const char* nume) {
		fin = fopen(nume, "r");
		buff = new char[4096]();
		sp = 4095;
	}

	InParser& operator >> (int &n) {
		char c;
		while (!isdigit(c = read_ch()) && c != '-');
		int sgn = 1;
		if (c == '-') {
			n = 0;
			sgn = -1;
		} else {
			n = c - '0';
		}
		while (isdigit(c = read_ch())) {
			n = 10 * n + c - '0';
		}
		n *= sgn;
		return *this;
	}

	InParser& operator >> (long long &n) {
		char c;
		n = 0;
		while (!isdigit(c = read_ch()) && c != '-');
		long long sgn = 1;
		if (c == '-') {
			n = 0;
			sgn = -1;
		} else {
			n = c - '0';
		}
		while (isdigit(c = read_ch())) {
			n = 10 * n + c - '0';
		}
		n *= sgn;
		return *this;
	}
};
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()
{
    InParser f("ograzi.in");
    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;
}