#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
set<pair<int, int>> mp;
set<pair<int, int>> blocked;
void check_and_mark(pair<int, int> pos) {
if (mp.count(pos) &&
mp.count({pos.first - 1, pos.second}) &&
mp.count({pos.first, pos.second - 1}) &&
mp.count({pos.first - 1, pos.second - 1})) {
blocked.insert(pos);
blocked.insert({pos.first - 1, pos.second});
blocked.insert({pos.first, pos.second - 1});
blocked.insert({pos.first - 1, pos.second - 1});
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, k, q;
cin >> n >> m >> k >> q;
vector<pair<int,int>> pos(k);
for (int i = 0; i < k; i++) {
cin >> pos[i].first >> pos[i].second;
mp.insert(pos[i]);
}
for (int i = 0; i < k; i++) {
check_and_mark(pos[i]);
}
cout << mp.size() - blocked.size() << "\n";
for (int i = 0; i < q; i++) {
int x0, y0;
cin >> x0 >> y0;
if (mp.count({x0, y0})) {
mp.erase({x0, y0});
} else {
mp.insert({x0, y0});
}
for (int x = x0 - 1; x <= x0 + 1; x++) {
for (int y = y0 - 1; y <= y0 + 1; y++) {
blocked.erase({x, y});
}
}
for (int x = x0 - 1; x <= x0 + 1; x++) {
for (int y = y0 - 1; y <= y0 + 1; y++) {
check_and_mark({x, y});
}
}
/* for (int i = 1; i < 10; i++) {
for (int j = 1; j < 10; j++) {
cout << (mp.count({i, j}) ? "#" : ".");
}
cout << "\n";
}
cout << "---\n";
for (int i = 1; i < 10; i++) {
for (int j = 1; j < 10; j++) {
cout << (blocked.count({i, j}) ? "#" : ".");
}
cout << "\n";
}*/
cout << mp.size() - blocked.size() << "\n";
}
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 74 75 | #include <iostream> #include <algorithm> #include <vector> #include <math.h> #include <set> using namespace std; typedef long long ll; set<pair<int, int>> mp; set<pair<int, int>> blocked; void check_and_mark(pair<int, int> pos) { if (mp.count(pos) && mp.count({pos.first - 1, pos.second}) && mp.count({pos.first, pos.second - 1}) && mp.count({pos.first - 1, pos.second - 1})) { blocked.insert(pos); blocked.insert({pos.first - 1, pos.second}); blocked.insert({pos.first, pos.second - 1}); blocked.insert({pos.first - 1, pos.second - 1}); } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, m, k, q; cin >> n >> m >> k >> q; vector<pair<int,int>> pos(k); for (int i = 0; i < k; i++) { cin >> pos[i].first >> pos[i].second; mp.insert(pos[i]); } for (int i = 0; i < k; i++) { check_and_mark(pos[i]); } cout << mp.size() - blocked.size() << "\n"; for (int i = 0; i < q; i++) { int x0, y0; cin >> x0 >> y0; if (mp.count({x0, y0})) { mp.erase({x0, y0}); } else { mp.insert({x0, y0}); } for (int x = x0 - 1; x <= x0 + 1; x++) { for (int y = y0 - 1; y <= y0 + 1; y++) { blocked.erase({x, y}); } } for (int x = x0 - 1; x <= x0 + 1; x++) { for (int y = y0 - 1; y <= y0 + 1; y++) { check_and_mark({x, y}); } } /* for (int i = 1; i < 10; i++) { for (int j = 1; j < 10; j++) { cout << (mp.count({i, j}) ? "#" : "."); } cout << "\n"; } cout << "---\n"; for (int i = 1; i < 10; i++) { for (int j = 1; j < 10; j++) { cout << (blocked.count({i, j}) ? "#" : "."); } cout << "\n"; }*/ cout << mp.size() - blocked.size() << "\n"; } return 0; } |
English