Cod sursa(job #2932084)

Utilizator robertanechita1Roberta Nechita robertanechita1 Data 1 noiembrie 2022 21:18:19
Problema Ograzi Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.1 kb
#include <bits/stdc++.h>

using namespace std;

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

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);
            }
        }
};

int n, m, w, h;
const int c1 = 43, c2 = 19, mod = 14411;
struct Elem{
    int x, y;
};
vector <Elem> L[15005];

int Find(int a, int b, int x, int y){
    int poz = (a * c1 + b * c2) % mod;
    for(auto e : L[poz])
        return (x >= e.x && x <= e.x + h && y >= e.y && y <= e.y + w);
}

void Read(){
//    std::ios::sync_with_stdio(false);
//    fin.tie (nullptr);
    InputReader fin("ograzi.in");
    fin >> n >> m >> w >> h;
    Elem e;
    for(int i = 1; i <= n; i++){
        fin >> e.x >> e.y;
        int a = e.x / h;
        int b = e.y / w;
        int poz = (a * c1 + b * c2) % mod;
        L[poz].push_back(e);
        ///dreptunghi
    }
    int x, y;
    int sol = 0;
    for(int i = 1; i <= m; i++){
        fin >> x >> y;
        int a = x / h;
        int b = y / w;
        sol += Find(a, b, x, y);
        sol += Find(a - 1, b, x, y);
        sol += Find(a, b - 1, x, y);
        sol += Find(a - 1, b - 1, x, y);
    }
    fout << sol << "\n";
    fout.close();
}

int main()
{
    Read();
    return 0;
}