Cod sursa(job #2639959)

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

using namespace std;

ifstream cin ("ograzi.in");
ofstream cout ("ograzi.out");

const int MOD = 14717;
const int P = 97;

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

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

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() {
  cin >> n >> m >> w >> h;
  for(int i = 1; i <= n; i++) {
    cin >> x >> y;
    table[cod(x / w + 1, y / h + 1)].push_back({x, y});
  }
  ans = 0;
  for(int i = 1; i <= m; i++) {
    cin >> x >> 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);
  }
  cout << ans << "\n";
}

int main() {
  // tester();
  solve();
  return 0;
}