Submission
Status:
[PPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: Ninstroyer
Problemset: fireball
Language: cpp
Time: 0.003 second
Submitted On: 2025-12-25 14:18:39
#include<bits/stdc++.h>
using namespace std;
const int nx = 105;
vector<pair<int,int>> dir = { {0,1}, {0,-1}, {1,0}, {-1,0} };
int main()
{
ios::sync_with_stdio(false), cin.tie(0);
int n, m, q; cin>>n>>m>>q;
int city = 0;
vector<vector<int>> arr(nx,vector<int>(nx,0));
for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) cin>>arr[i][j], city += arr[i][j];
queue<pair<int,int>> qu;
while(q--)
{
int land = 0;
int r, c; cin>>r>>c;
if(arr[r][c] == 1) land++, arr[r][c] = 0, qu.push({r,c});
while(!qu.empty())
{
auto [row,column] = qu.front();
qu.pop();
for(auto [rr, cc] : dir)
{
int dr = row + rr;
int dc = column + cc;
if(arr[dr][dc] == 1)
{
qu.push({dr,dc});
land++;
arr[dr][dc] = 0;
}
}
}
city -= land;
cout<<city<<endl;
}
}