Cod sursa(job #3040427)

Utilizator AztecaVlad Tutunaru 2 Azteca Data 29 martie 2023 21:12:01
Problema Ograzi Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.82 kb
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <cassert>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>
#include <numeric>

using namespace std;

typedef long long ll;
const int MOD = 38461;
const int P = 100;
vector<pair<int, int>> mp[MOD];
int n, m, w, h;

int ret = 0;

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

void baga(int nr, int x, int y) {
        for (auto &it : mp[nr]) {
                if (it.first <= x && x <= it.first + w && it.second <= y && y <= it.second + h) {
                        ret++;
                        return;
                }
        }
}

signed main() {
#ifdef INFOARENA
        ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        freopen("ograzi.in", "r", stdin);
        freopen("ograzi.out", "w", stdout);
#else
        FILE* stream;
        freopen_s(&stream, "input.txt", "r", stdin);
#endif
        cin >> n >> m >> w >> h;
        for (int i = 1; i <= n; i++) {
                int l, c;
                cin >> l >> c;
                mp[getcode(l / w + 1, c / h + 1)].push_back({l, c});
        }
        ret = 0;
        for (int i = 1; i <= m; i++) {
                int x, y;
                cin >> x >> y;
                baga(getcode(x / w + 1, y / h + 1), x, y);
                baga(getcode(x / w, y / h + 1), x, y);
                baga(getcode(x / w + 1, y / h), x, y);
                baga(getcode(x / w, y / h), x, y);
        }
        cout << ret << "\n";
        return 0;
}