Submission
Status:
[PPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: poni
Problemset: fireball
Language: cpp
Time: 0.004 second
Submitted On: 2026-10-08 13:36:12
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
cin.tie(0)->sync_with_stdio(0);
int m, n, q;
cin >> m >> n >> q;
pair<int, int> dir[4] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
int total = 0;
bool a[m][n];
for (auto &i : a) {
for (auto &j : i) {
cin >> j;
total += j;
}
}
int ans[q];
for (int i = 0; i < q; i++) {
int x, y, cnt = 0;
cin >> x >> y;
--x,--y;
if (!a[x][y]) {
ans[i] = total;
continue;
}
queue<pair<int, int>> q;
q.push({x, y});
a[x][y] = 0;
while (!q.empty()) {
auto [ci, cj] = q.front();
q.pop();
cnt++;
for (auto [di, dj] : dir) {
int ni = di+ci, nj = dj+cj;
if (ni < 0 || nj < 0 || ni >= m || nj >= n) continue;
if (!a[ni][nj]) continue;
a[ni][nj] = 0;
q.push({ni, nj});
}
}
total -= cnt;
ans[i] = total;
}
for (auto &i : ans) cout << i << "\n";
}