Submission

Status:

[PP-SSSSSSSSSSSS]

Subtask/Task Score:

{0/100}

Score: 0

User: KantaponZ

Problemset: fireball

Language: cpp

Time: 0.003 second

Submitted On: 2025-09-01 22:50:37

#include <bits/stdc++.h>
using namespace std;

int N, M, Q;
bool vis[105][105];
int ct = 0;
queue<pair<int,int>> q;
int xx[4] = {1, -1, 0, 0};
int yy[4] = {0, 0, 1, -1};

void BFS(int x, int y) {
    if (vis[x][y]) return;
    q.emplace(x, y);
    while (!q.empty()) {
        auto [x, y] = q.front();
        q.pop();
        ct--;
        for (int i = 0; i < 3; i++) {
            int nx = x + xx[i], ny = y + yy[i];
            if (nx < 1 || ny < 1 || nx > N || ny > M) continue;
            if (vis[nx][ny]) continue;
            q.emplace(nx, ny);
            vis[nx][ny] = 1;
        }
    }

}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> N >> M >> Q;
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= M; j++) {
            int x; cin >> x;
            if (x == 0) {
                vis[i][j] = 1;
            } else {
                ct++;
            }
        }
    }
    while (Q--) {
        int x; int y;
        cin >> x >> y;
        BFS(x, y);
        cout << ct << "\n";
    }
}