Cod sursa(job #3132108)

Utilizator AlexandruBenescuAlexandru Benescu AlexandruBenescu Data 21 mai 2023 23:19:41
Problema Ograzi Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <bits/stdc++.h>
#define MOD 500009
#define L 707
using namespace std;
ifstream fin("ograzi.in");
ofstream fout("ograzi.out");

int n, m, w, h, ans;
vector <pair <int, int>> v[MOD];

inline int shusta(int x, int y){
  return (x * L + y) % MOD;
}

inline void add(int x, int y, int place){
  for (auto it : v[place])
    if (it.first <= x && x <= it.first + w && it.second <= y && y <= it.second + h){
      ans++;
      return;
    }
}

int main(){
  fin >> n >> m >> w >> h;
  for (int i = 1; i <= n; i++){
    int x, y;
    fin >> x >> y;
    v[shusta(x / w + 1, y / h + 1)].push_back({x, y});
  }
  for (int i = 1; i <= m; i++){
    int x, y;
    fin >> x >> y;
    add(x, y, shusta(x / w + 1, y / h + 1));
    add(x, y, shusta(x / w, y / h + 1));
    add(x, y, shusta(x / w + 1, y / h));
    add(x, y, shusta(x / w, y / h));
  }
  fout << ans << "\n";
  return 0;
}