Cod sursa(job #2639964)

Utilizator lucametehauDart Monkey lucametehau Data 4 august 2020 16:38:16
Problema Ograzi Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.44 kb
#include <cstdio>
#include <algorithm>
#include <queue>
#include <random>
#include <chrono>
#define x first
#define y second

using namespace std;

const int MOD = 100003;
const int P = 97;
const int DIM = (1 << 17);

int n, m, w, h, ans;
int x, y;

vector <pair <int, int>> table[MOD];

char nxt() {
  static char buff[DIM];
  static int bp = DIM;
  if(bp == DIM) {
    fread(buff, 1, DIM, stdin);
    bp = 0;
  }
  return buff[bp++];
}

void read(int &x) {
  static char c;
  x = 0;
  do {
    c = nxt();
  } while(c < '0' || '9' < c);
  do {
    x = x * 10 + c - '0';
    c = nxt();
  } while(c >= '0' && c <= '9');
}

int cod(int x, int y) {
  return (x * P + y) % MOD;
}

void check(int nr, int x, int y) {
  for(auto &i : table[nr]) {
    if(i.x <= x && x <= i.x + w && i.y <= y && y <= i.y + h) {
      ans++;
      return;
    }
  }
}

void solve() {
  read(n), read(m), read(w), read(h);
  for(int i = 1; i <= n; i++) {
    read(x), read(y);
    table[cod(x / w + 1, y / h + 1)].push_back({x, y});
  }
  ans = 0;
  for(int i = 1; i <= m; i++) {
    read(x), read(y);
    check(cod(x / w + 1, y / h + 1), x, y);
    check(cod(x / w, y / h + 1), x, y);
    check(cod(x / w + 1, y / h), x, y);
    check(cod(x / w, y / h), x, y);
  }
  printf("%d\n", ans);
}

int main() {
  freopen("ograzi.in", "r", stdin);
  freopen("ograzi.out", "w", stdout);
  // tester();
  solve();
  return 0;
}