#include <bits/stdc++.h>
using namespace std;
int n, m, k, q;
typedef long long ll;
unordered_set<ll> blocks;
ll hsh(int x, int y) {
ll r = x;
r <<= 32;
r += y;
return r;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> k >> q;
for(int i = 0; i < k; i++) {
int x, y;
cin >> x >> y;
blocks.insert(hsh(x, y));
}
for(int i = -1; i < q; i++) {
unordered_set<ll> blocks_copy = blocks;
int last_size = blocks_copy.size();
do {
last_size = blocks_copy.size();
vector<ll> to_rm;
for(auto b: blocks_copy) {
int x = b>>32;
int y = b&0x0000FFFF;
if(
(blocks_copy.find(hsh(x, y - 1)) == blocks_copy.end() && blocks_copy.find(hsh(x, y + 1)) == blocks_copy.end())
|| (blocks_copy.find(hsh(x + 1, y)) == blocks_copy.end() && blocks_copy.find(hsh(x - 1, y)) == blocks_copy.end())
) {
to_rm.push_back(hsh(x, y));
}
}
for(auto b: to_rm) {
int x = b>>32;
int y = b&0x0000FFFF;
blocks_copy.erase(hsh(x, y));
}
} while(blocks_copy.size() != last_size);
cout << blocks.size() - blocks_copy.size() << "\n";
int x, y;
cin >> x >> y;
if(blocks.find(hsh(x, y)) == blocks.end()) {
blocks.insert(hsh(x, y));
} else {
blocks.erase(hsh(x, y));
}
}
return 0;
}
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 | #include <bits/stdc++.h> using namespace std; int n, m, k, q; typedef long long ll; unordered_set<ll> blocks; ll hsh(int x, int y) { ll r = x; r <<= 32; r += y; return r; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> k >> q; for(int i = 0; i < k; i++) { int x, y; cin >> x >> y; blocks.insert(hsh(x, y)); } for(int i = -1; i < q; i++) { unordered_set<ll> blocks_copy = blocks; int last_size = blocks_copy.size(); do { last_size = blocks_copy.size(); vector<ll> to_rm; for(auto b: blocks_copy) { int x = b>>32; int y = b&0x0000FFFF; if( (blocks_copy.find(hsh(x, y - 1)) == blocks_copy.end() && blocks_copy.find(hsh(x, y + 1)) == blocks_copy.end()) || (blocks_copy.find(hsh(x + 1, y)) == blocks_copy.end() && blocks_copy.find(hsh(x - 1, y)) == blocks_copy.end()) ) { to_rm.push_back(hsh(x, y)); } } for(auto b: to_rm) { int x = b>>32; int y = b&0x0000FFFF; blocks_copy.erase(hsh(x, y)); } } while(blocks_copy.size() != last_size); cout << blocks.size() - blocks_copy.size() << "\n"; int x, y; cin >> x >> y; if(blocks.find(hsh(x, y)) == blocks.end()) { blocks.insert(hsh(x, y)); } else { blocks.erase(hsh(x, y)); } } return 0; } |
English