#include <deque>
#include <iostream>
#include <queue>
#include <unordered_set>
template <>
struct std::hash<std::pair<int32_t, int32_t>> {
size_t operator()(const std::pair<int32_t, int32_t> &p) const noexcept {
auto h = std::hash<int32_t>();
return h(p.first) ^ (h(p.second) << 1);
}
};
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int32_t n, m, k, q;
std::cin >> n >> m >> k >> q;
std::unordered_set<std::pair<int32_t, int32_t>> blocks;
for (int32_t i = 0; i < k; ++i) {
int32_t x, y;
std::cin >> x >> y;
blocks.emplace(x, y);
}
std::deque<std::pair<int32_t, int32_t>> moves;
for (int32_t i = 0; i < q; ++i) {
int32_t x, y;
std::cin >> x >> y;
moves.emplace_back(x, y);
}
for (;;) {
auto blocks_iter = blocks;
start:
for (auto b: blocks_iter) {
if ((blocks_iter.count({b.first - 1, b.second}) == 0 &&
blocks_iter.count({b.first + 1, b.second}) == 0) ||
(blocks_iter.count({b.first, b.second - 1}) == 0 &&
blocks_iter.count({b.first, b.second + 1}) == 0)) {
blocks_iter.erase(b);
goto start;
}
}
// for (auto b: blocks) {
// std::queue<std::pair<int32_t, int32_t>> squared;
// if (blocks.count({b.first + 1, b.second}) > 0 &&
// blocks.count({b.first, b.second + 1}) > 0 &&
// blocks.count({b.first + 1, b.second + 1}) > 0) {
// squared.push(b);
// squared.push({b.first + 1, b.second});
// squared.push({b.first, b.second + 1});
// squared.push({b.first + 1, b.second + 1});
// }
// }
std::cout << blocks.size() - blocks_iter.size() << "\n";
if (moves.empty()) {
break;
}
auto m = moves.front();
moves.pop_front();
if (blocks.count(m) > 0) {
blocks.erase(m);
} else {
blocks.insert(m);
}
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | #include <deque> #include <iostream> #include <queue> #include <unordered_set> template <> struct std::hash<std::pair<int32_t, int32_t>> { size_t operator()(const std::pair<int32_t, int32_t> &p) const noexcept { auto h = std::hash<int32_t>(); return h(p.first) ^ (h(p.second) << 1); } }; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int32_t n, m, k, q; std::cin >> n >> m >> k >> q; std::unordered_set<std::pair<int32_t, int32_t>> blocks; for (int32_t i = 0; i < k; ++i) { int32_t x, y; std::cin >> x >> y; blocks.emplace(x, y); } std::deque<std::pair<int32_t, int32_t>> moves; for (int32_t i = 0; i < q; ++i) { int32_t x, y; std::cin >> x >> y; moves.emplace_back(x, y); } for (;;) { auto blocks_iter = blocks; start: for (auto b: blocks_iter) { if ((blocks_iter.count({b.first - 1, b.second}) == 0 && blocks_iter.count({b.first + 1, b.second}) == 0) || (blocks_iter.count({b.first, b.second - 1}) == 0 && blocks_iter.count({b.first, b.second + 1}) == 0)) { blocks_iter.erase(b); goto start; } } // for (auto b: blocks) { // std::queue<std::pair<int32_t, int32_t>> squared; // if (blocks.count({b.first + 1, b.second}) > 0 && // blocks.count({b.first, b.second + 1}) > 0 && // blocks.count({b.first + 1, b.second + 1}) > 0) { // squared.push(b); // squared.push({b.first + 1, b.second}); // squared.push({b.first, b.second + 1}); // squared.push({b.first + 1, b.second + 1}); // } // } std::cout << blocks.size() - blocks_iter.size() << "\n"; if (moves.empty()) { break; } auto m = moves.front(); moves.pop_front(); if (blocks.count(m) > 0) { blocks.erase(m); } else { blocks.insert(m); } } } |
English