Submission
Status:
[PPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: vachirasawin
Problemset: fireball
Language: cpp
Time: 0.002 second
Submitted On: 2026-03-13 02:27:16
// grader-chan
// c2_knb64_fireball.cpp | c2_knb64_fireball
#include <bits/stdc++.h>
using namespace std;
int N, M, Q;
int world[100][100];
int land = 0;
int dr[] = {+1, 0, -1, 0};
int dc[] = {0, +1, 0, -1};
int destroyAndCount(int r, int c) {
int countLand = 0;
queue<pair<int, int>> q;
q.push({r, c});
world[r][c] = 0;
countLand++;
while (!q.empty()) {
pair<int, int> curr = q.front();
q.pop();
for (int i = 0; i < 4; i++) {
int nr = curr.first + dr[i];
int nc = curr.second + dc[i];
if (nr >= 0 && nr < N && nc >= 0 && nc < M && world[nr][nc] == 1) {
world[nr][nc] = 0;
countLand++;
q.push({nr, nc});
}
}
}
return countLand;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> N >> M >> Q;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
int status;
cin >> status;
if (status == 1) land++;
world[i][j] = status;
}
}
while (Q--) {
int x, y;
cin >> x >> y;
x--; y--;
if (world[x][y] == 1) {
int destroy = destroyAndCount(x, y);
land -= destroy;
}
cout << land << endl;
}
return 0;
}