Submission

Status:

[PP-SSSSSSSSSSSS]

Subtask/Task Score:

{0/100}

Score: 0

User: Ecir

Problemset: fireball

Language: cpp

Time: 0.002 second

Submitted On: 2025-10-04 09:44:42

#include <bits/stdc++.h>
using namespace std;
#define twod array<int,2>
int dx[]={0,1,0,-1};
int dy[]={-1,0,1,0};
bool arr[109][109];
int cnt=0;
int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int sy,sx,n;cin >> sy >> sx >> n;
    for(int i=1;i<=sy;i++){
        for(int j=1;j<=sx;j++){
            cin >> arr[i][j];
            if(arr[i][j]==1) cnt++;
        }
    }
    while(n--){
        int y,x;cin >> y >> x;
        queue<twod> q;
        q.push({y,x});
        while(!q.empty()){
            auto m=q.front();q.pop();
            int u=m[0],v=m[1];
            if(arr[u][v]==1){
                arr[u][v]=0;
                cnt--;
            }
            else continue;
            for(int i=0;i<=3;i++){
                int yy=y+dy[i],xx=x+dx[i];
                if(yy>=1 && yy<=sy && xx>=1 && xx<=sx) q.push({yy,xx});
            }
        }
        cout << cnt << '\n';
    }

    return 0;
}