Submission
Status:
[PPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: SnowAveNode
Problemset: fireball
Language: cpp
Time: 0.002 second
Submitted On: 2026-04-10 18:04:59
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int nx = 1e5 + 5, MOD = 1e9 + 7, inf = 2e9; const ll INF = 4e18;
int dy[] = {-1, 1, 0, 0}, dx[] = {0, 0, -1, 1};
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, m, q; cin >> n >> m >> q; ll cnt = 0;
vector<vector<int>> grid(n, vector<int>(m));
for(auto &x : grid) for(auto &y : x) {
cin >> y; cnt += y;
}
while(q--) {
int sy, sx; cin >> sy >> sx; sy--; sx--;
if(grid[sy][sx] == 1) {
stack<pair<int, int>> st;
st.push({sy, sx});
grid[sy][sx] = 0;
cnt--;
while(!st.empty()) {
auto [y, x] = st.top(); st.pop();
for(int k = 0; k < 4; k++) {
int ny = y + dy[k], nx = x + dx[k];
if(ny < 0 || ny >= n || nx < 0 || nx >= m) continue;
if(grid[ny][nx] != 1) continue;
grid[ny][nx] = 0;
cnt--;
st.push({ny, nx});
}
}
}
cout << cnt << '\n';
}
return 0;
}