Cod sursa(job #2054655)

Utilizator alexpetrescuAlexandru Petrescu alexpetrescu Data 2 noiembrie 2017 11:55:49
Problema Ograzi Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.51 kb
#include <cstdio>
#include <unordered_map>
#include <cctype>

FILE *fin = fopen("ograzi.in", "r"), *fout = fopen("ograzi.out", "w");

#define BUF_SIZE 1 << 17

int pos = BUF_SIZE;
char buf[BUF_SIZE];

inline char nextch() {
    if (pos == BUF_SIZE) fread(buf, BUF_SIZE, 1, fin), pos = 0;
    return buf[pos++];
}

inline int read() {
    char ch;
    while (!isdigit(ch = nextch()));
    int x = ch - '0';
    while (isdigit(ch = nextch())) x = 10 * x + ch - '0';
    return x;
}

#define ll long long

std::unordered_map <ll, ll> mp;

int w, h;
bool o;

inline ll conf(ll x, int y) {
    if (x < 0 || y < 0) return 0;
    else return (x << 30) + y;
}

inline bool este(ll c, int x, int y) {
    if (c == 0 && !o) return 0;
    int a = c >> 30, b = c & ((1 << 30) - 1);
    return (x - a <= w && y - b <= h && a <= x && b <= y);
}

int main() {
    int n = read();
    int m = read();
    w = read();
    h = read();

    for (int i = 0; i < n; i++) {
        int x = read();
        int y = read();

        mp[conf(x / w, y / h)] = conf(x, y);

        if (x == 0 && y == 0)
            o = 1;
    }

    int ans = 0;
    for (int i = 0; i < m; i++) {
        int x = read();
        int y = read();

        ans += este(mp[conf(x / w, y / h)], x, y) || este(mp[conf(x / w, y / h - 1)], x, y) || este(mp[conf(x / w - 1, y / h)], x, y) || este(mp[conf(x / w - 1, y / h - 1)], x, y);
    }

    fprintf(fout, "%d\n", ans);

    fclose(fin);
    fclose(fout);
    return 0;
}