Submission

Status:

[PPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: SnowAveNode

Problemset: fireball

Language: cpp

Time: 0.003 second

Submitted On: 2026-03-02 09:47:12

#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
using namespace std;

int dy[] = {-1, 1, 0, 0}, dx[] = {0, 0, -1, 1};

int main() {

    int n, m, Q; cin >> n >> m >> Q; int land = 0;
    vector<vector<ll>> v(n, vector<ll>(m));
    for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) {
        cin >> v[i][j];
        if(v[i][j]) land++;
    }

    while(Q--) {
        queue<pii> q;
        int r, c; cin >> r >> c; r--; c--;
        if(v[r][c] == 1) {
            q.push({r, c}); v[r][c] = 2; land--;

            while(!q.empty()) {
                auto [y, x] = q.front(); q.pop();
                for(int k = 0; k < 4; k++) {
                    int ny = y + dy[k], nx = x + dx[k];
                    if(ny < 0 || ny >= n || nx < 0 || nx >= m) continue;
                    if(v[ny][nx] != 1) continue;
                    v[ny][nx] = 2; land--;
                    q.push({ny, nx});
                }
            }
        }

        cout << land << endl;
    }

    return 0;
}