Submission
Status:
[PPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: Shangbin
Problemset: fireball
Language: cpp
Time: 0.002 second
Submitted On: 2026-03-09 22:44:37
//Problem = https://grader.gchan.moe/problemset/c2_knb64_fireball/statement
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
const int maxn = 105;
int n, m, ques, x, y, city_cnt = 0, dir[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
bool mat[maxn][maxn];
bool inMap(pii pos){
auto [i, j] = pos;
return i >= 1 && i <= n && j >= 1 && j <= m;
}
void dfs(pii pos){
auto [i, j] = pos;
if (mat[i][j] == 0) return;
mat[i][j] = 0;
city_cnt--;
for (auto [ni, nj] : dir){
ni += i, nj += j;
if (inMap({ni, nj})) dfs({ni, nj});
}
}
int main(){
cin.tie(nullptr)->sync_with_stdio(0);
cin >> n >> m >> ques;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
cin >> mat[i][j];
if (mat[i][j] == 1) city_cnt++;
}
}
while (ques--){
cin >> x >> y;
dfs({x, y});
cout << city_cnt << '\n';
}
}