Submission
Status:
[PPPPPPPPPPPPxSS]
Subtask/Task Score:
{0/100}
Score: 0
User: C12
Problemset: fireball
Language: cpp
Time: 0.003 second
Submitted On: 2025-12-31 18:46:38
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pii pair<ll,ll>
#define puii pair<ull,ull>
#define piii pair<ll,pii>
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define mpiii(a,b,c) make_pair(a,make_pair(b,c));
ll mod = 1000000007;
int board[100][100];
int cnt = 0;
int posx[4] = {-1,1,0,0};
int posy[4] = {0,0,-1,1};
void solve(){
ll n,m,q;
cin >> n >> m >> q;
for(int i = 0;i < n;i++){
for(int j = 0;j < m;j++){
cin >> board[i][j];
if(board[i][j] == 1){
cnt++;
}
}
}
int x,y,nx,ny;
queue<pii>que;
while(q--){
cin >> x >> y;
x--;
y--;
if(board[x][y] == 1){
board[x][y] = 0;
cnt--;
que.push(mp(x,y));
while(!que.empty()){
x = que.front().first;
y = que.front().second;
que.pop();
for(int i = 0;i < 4;i++){
nx = x + posx[i];
ny = y + posy[i];
if(board[nx][ny] == 1){
board[nx][ny] = 0;
cnt--;
que.push(mp(nx,ny));
}
}
}
}
cout << cnt << '\n';
}
return;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ll q;
// cin >> q;
// while(q--)
solve();
return 0;
}