Submission

Status:

[PPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: C12

Problemset: fireball

Language: cpp

Time: 0.005 second

Submitted On: 2025-12-31 18:47:38

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

#define f first
#define s second
#define pii pair<ll,ll>
#define puii pair<ull,ull>
#define piii pair<ll,pii>
#define ll long long
#define ull unsigned long long
#define mp make_pair
 
#define mpiii(a,b,c) make_pair(a,make_pair(b,c));
ll mod = 1000000007;

int board[100][100];
int cnt = 0;

int posx[4] = {-1,1,0,0};
int posy[4] = {0,0,-1,1};

void solve(){
    ll n,m,q;

    cin >> n >> m >> q;

    for(int i = 0;i < n;i++){
        for(int j = 0;j < m;j++){
            cin >> board[i][j];
            if(board[i][j] == 1){
                cnt++;
            }
        }
    }

    int x,y,nx,ny;
    queue<pii>que;

    while(q--){
        cin >> x >> y;
        x--;
        y--;
        if(board[x][y] == 1){
            board[x][y] = 0;
            cnt--;
            que.push(mp(x,y));
            while(!que.empty()){
                x = que.front().first;
                y = que.front().second;
                que.pop();
                for(int i = 0;i < 4;i++){
                    nx = x + posx[i];
                    ny = y + posy[i];
                    if(nx >= n || ny >= m || nx < 0 || ny < 0) continue;
                    if(board[nx][ny] == 1){
                        board[nx][ny] = 0;
                        cnt--;
                        que.push(mp(nx,ny));
                    }
                }
            }
        }
        cout << cnt << '\n';
    }

    return;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    ll q;
 
    // cin >> q;

    // while(q--)
        solve(); 

    return 0;
}