Submission
Status:
[PPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: qweqwe
Problemset: fireball
Language: cpp
Time: 0.002 second
Submitted On: 2025-10-22 15:52:02
#include <bits/stdc++.h>
#define speed cin.tie(0)->sync_with_stdio(0)
#define ll long long
#define pii pair<int,int>
using namespace std;
int dx[4]={0,0,1,-1},
dy[4]={1,-1,0,0};
int cnt=0;
vector<vector<int>> land(101,vector<int>(101));
int n,m,q;
void dfs(int x,int y){
land[x][y]=0;cnt--;
for (int j=0;j<4;j++){
int nx=x+dx[j],ny=y+dy[j];
if (nx>=0 && nx<n && ny>=0 && ny<m && land[nx][ny]){
dfs(nx,ny);
}
}
}
int main(){
speed;
cin >> n >> m >> q;
for (int i=0;i<n;i++){
for (int j=0;j<m;j++){
cin >> land[i][j];
if (land[i][j]) cnt++;
}
}
for (int i=0;i<q;i++){
int x,y;cin >> x >> y;
x--;y--;
if (land[x][y]) dfs(x,y);
cout << cnt << "\n";
}
return 0;
}