Submission

Status:

[PPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: iij

Problemset: fireball

Language: cpp

Time: 0.003 second

Submitted On: 2025-10-22 22:11:10

#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(n, vector<bool>(m));

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            bool t;
            cin >> t;
            v[i][j] = t;
            if (t) c++;
        }
    }

    while (q--)
    {
        int x, y;
        cin >> x >> y;
        x--;y--;
        if (v[x][y]) dfsSet0(v, x, y);
        cout << c << "\n";
    }
}