D
CSP_SAKME
·
·
个人记录
#include<bits/stdc++.h>
using namespace std;
struct Grid {
int H, W;
unordered_map<int, vector<int>> row_to_cols;
unordered_map<int, vector<int>> col_to_rows;
vector<bool> row_cleared;
vector<bool> col_cleared;
Grid(int h, int w) : H(h), W(w),
row_cleared(h+1, false), col_cleared(w+1, false) {}
void add_garbage(int x, int y) {
row_to_cols[x].push_back(y);
col_to_rows[y].push_back(x);
}
int process_query(int type, int idx) {
if (type == 1) {
if (row_cleared[idx]) return 0;
int count = 0;
for (int y : row_to_cols[idx]) {
if (!col_cleared[y]) count++;
}
row_cleared[idx] = true;
return count;
} else {
if (col_cleared[idx]) return 0;
int count = 0;
for (int x : col_to_rows[idx]) {
if (!row_cleared[x]) count++;
}
col_cleared[idx] = true;
return count;
}
}
};
int main() {
int H, W, N;
cin >> H >> W >> N;
Grid gm(H, W);
for (int i = 0; i < N; ++i) {
int X, Y;
cin >> X >> Y;
gm.add_garbage(X, Y);
}
int Q;
cin >> Q;
while (Q--) {
int type, idx;
cin >> type >> idx;
cout << gm.process_query(type, idx) << endl;
}
return 0;
}