Cod sursa(job #2668040)

Utilizator PatrickCplusplusPatrick Kristian Ondreovici PatrickCplusplus Data 4 noiembrie 2020 13:08:01
Problema Ograzi Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.06 kb
#include <bits/stdc++.h>

using namespace std;

ofstream fout("ograzi.out");

const int sigma = 997, mod = 100003;
int n, m, w, h;
vector <pair <int, int> > H[mod + 5];

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

bool Find(int x, int y, pair <int, int> p){
    if (x < 0 || y < 0) return false;
    int val = (x * sigma + y) % mod;
    for (auto it : H[val]){
        if (p.first <= it.first + w && p.first >= it.first && p.second <= it.second + h && p.second >= it.second){
            return true;
        }
    }
    return false;
}

int main(){
    InputReader fin("ograzi.in");
    fin >> n >> m >> w >> h;
    for (int i = 1; i <= n; ++i){
        int x, y;
        fin >> x >> y;
        int val = (x / w * sigma + y / h) % mod;
        H[val].push_back({x, y});
    }
    int contor = 0;
    for (int i = 1; i <= m; ++i){
        int x, y;
        fin >> x >> y;
        pair <int, int> aux = {x, y};
        x /= w;
        y /= h;
        if (Find(x, y, aux) || Find(x - 1, y, aux) || Find(x, y - 1, aux) || Find(x - 1, y - 1, aux)){
            ++contor;
        }
    }
    fout << contor << "\n";
    fout.close();
    return 0;
}