Submission

Status:

[PPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: NovemNotes

Problemset: fireball

Language: cpp

Time: 0.003 second

Submitted On: 2026-03-12 11:31:53

#include <bits/stdc++.h>
using namespace std;

#define int long long
const int N = 109;

int n,m,q;
int cnt=0;
vector<pair<int,int>> vp = {{1,0},{-1,0},{0,1},{0,-1}};
int grid[N][N];

void solve(int x,int y){
    if(!grid[x][y])return ;
    queue<pair<int,int>> q;
    q.emplace(x,y);cnt--;
    grid[x][y]=0;
    while(!q.empty()){
        auto [x,y] = q.front(); q.pop();
        for(auto [nx,ny] : vp){
            nx+=x,ny+=y;
            if(nx<1||ny<1||nx>n||ny>m||!grid[nx][ny])continue;
            grid[nx][ny]=0;
            cnt--;
            q.emplace(nx,ny);
        }
    }
}

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin >> n >> m >> q;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin >> grid[i][j];
            if(grid[i][j])cnt++;
        }
    }
    while(q--){
        int a,b;cin >> a >> b;
        solve(a,b);
        cout << cnt << "\n";
    }
    return 0;
}