Submission
Status:
[PPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: foldnut
Problemset: fireball
Language: cpp
Time: 0.005 second
Submitted On: 2026-03-18 19:48:36
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n, m, q, tot, cnt, tb[N][N], vis[N][N], dx[] = {0, 0, -1, 1}, dy[] = {1, -1, 0, 0};
void dfs(int x, int y){
++cnt;
for(int i = 0;i<4;i++){
int nx = x + dx[i], ny = y + dy[i];
if(nx >= 1 && nx <= n && ny >= 1 && ny <= m && !vis[nx][ny] && tb[nx][ny] == 1){
vis[nx][ny] = 1;
dfs(nx, ny);
}
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m >> q;
for(int i = 1;i<=n;i++) for(int j = 1;j<=m;j++){
cin >> tb[i][j];
if(tb[i][j] == 1) ++tot;
}
while(q--){
int x, y; cin >> x >> y;
if(tb[x][y] == 1 && !vis[x][y]) vis[x][y] = 1, dfs(x, y);
cout << tot - cnt << '\n';
}
}