Submission
Status:
[-SSSSSSSSSSSSSS]
Subtask/Task Score:
{0/100}
Score: 0
User: Neozaawwman1
Problemset: fireball
Language: cpp
Time: 0.004 second
Submitted On: 2025-12-20 22:53:20
#include <bits/stdc++.h>
using namespace std;
int N, M, Q;
const int ex = 1005;
int mp[ex][ex];
int ct = 0;
queue<pair<int,int>> q;
int xx[4] = {-1,0,0,1};
int yy[4] = {0,-1,1,0};
void BFS(int x1, int y1){
q.push({x1,y1});
while(!q.empty()){
int x,y; tie(x,y)=q.front();q.pop();
mp[y][x] = 1;
ct--;
for(int i=0;i<4;i++){
int nx = x + xx[i];
int ny = y + yy[i];
if(nx<0 || ny<0 || nx>=M || ny>=N) continue;
if(mp[ny][nx] == 1) continue;
q.push({nx,ny});
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> M >> Q;
for(int i=0;i<N;i++){
for(int j=0;j<M;j++){
cin >> mp[i][j];
if(mp[i][j] == 0) ct++;
}
}
for(int i=0;i<Q;i++){
int a,b;
cin >> a >> b;
if(mp[a-1][b-1] == 0)
BFS(b-1, a-1);
cout << ct << "\n";
}
}