Submission

Status:

[PPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: colo39

Problemset: fireball

Language: cpp

Time: 0.004 second

Submitted On: 2026-11-21 12:26:46

#include <bits/stdc++.h>
using namespace std;
int table[105][105];
int ch[105][105];

int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n,m,q;
    cin >> n >> m >> q;
    int compo = 0;
    for (int i = 1;i <= n;i++) {
        for (int j =1;j <= m;j++) {
            int k;
            cin >> k;
            table[i][j] = k;
            if (k) compo++;
        }
    }
    while (q--) {
        int x,y;
        cin >> x >> y;
        if (table[x][y] && !ch[x][y]) {
            queue<pair<int,int>> q;
            q.push({x,y});
            ch[x][y] = 1;
            compo--;
            while (!q.empty()) {
                auto u = q.front();
                q.pop();
                for (int i = 0; i < 4;i++) {
                    pair<int,int> p = {u.first+dx[i],u.second+dy[i]};
                    if (!table[p.first][p.second] || ch[p.first][p.second]) continue;
                    ch[p.first][p.second] = 1;
                    compo--;
                    q.push(p);
                }
            }
        }
        cout << compo << "\n";
    }
    return 0;
}