Submission
Status:
[PPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: Hxluk.ka
Problemset: fireball
Language: cpp
Time: 0.003 second
Submitted On: 2026-03-15 22:24:59
#include <iostream>
#include <queue>
#include <utility>
using namespace std;
const int nx=103, dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
int n, m, mp[nx][nx], cnt, x, y;
void solve() {
cin>>x>>y;
if (mp[x][y]==0) {cout<<cnt<<'\n'; return;}
queue<pair<int, int>> q;
q.push({x, y});
mp[x][y]=0;
while (!q.empty()) {
auto [u, v]=q.front(); q.pop();
cnt--;
for (int i=0; i<4; i++) {
int ni=u+dir[i][0], nj=v+dir[i][1];
if (!mp[ni][nj]) continue;
mp[ni][nj]=0;
q.push({ni, nj});
}
}
cout<<cnt<<'\n';
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int q;
cin>>n>>m>>q;
for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) cin>>mp[i][j];
for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) if (mp[i][j]) cnt++;
while (q--) solve();
}