Submission
Status:
[PP-SSSSSSSSSSSS]
Subtask/Task Score:
{0/100}
Score: 0
User: iij
Problemset: fireball
Language: cpp
Time: 0.002 second
Submitted On: 2025-10-22 21:39:30
#include <iostream>
#include <vector>
using namespace std;
int n, m, c=0, dirs[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
void dfsSet0(vector<vector<bool>> &v, int x, int y) {
v[x][y] = 0;
c--;
for (auto &d : dirs) {
int nx = x + d[0], ny = y + d[1];
if (nx >= 0 && ny >= 0 && nx < n && ny < m && v[nx][ny]) dfsSet0(v, nx, ny);
}
}
int main() {
int q;
cin >> n >> m >> q;
vector<vector<bool>> v(m, vector<bool>(n));
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
bool t;
cin >> t;
v[i][j] = t;
if (t) c++;
}
}
while (q--)
{
int x, y;
cin >> x >> y;
if (v[--x][--y]) dfsSet0(v, x, y);
cout << c << "\n";
}
}