Cod sursa(job #2709592)

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


ofstream g ("ograzi.out");

vector <pair<int,int> > v[100005];
int n,m,w,h;
int rasp;

class InputReader {
public:
    InputReader() {}
    InputReader(const char *file_name) {
        input_file = fopen(file_name, "r");
        cursor = 0;
        fread(buffer, SIZE, 1, input_file);
    }
    inline InputReader &operator >>(int &n) {
        while(buffer[cursor] < '0' || buffer[cursor] > '9') {
            advance();
        }
        n = 0;
        while('0' <= buffer[cursor] && buffer[cursor] <= '9') {
            n = n * 10 + buffer[cursor] - '0';
            advance();
        }
        return *this;
    }
private:
    FILE *input_file;
    static const int SIZE = 1 << 17;
    int cursor;
    char buffer[SIZE];
    inline void advance() {
        ++ cursor;
        if(cursor == SIZE) {
            cursor = 0;
            fread(buffer, SIZE, 1, input_file);
        }
    }
};


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()
{
    InputReader f("ograzi.in");
    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;
}