Submission

Status:

[PPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: 12345678

Problemset: fireball

Language: cpp

Time: 0.002 second

Submitted On: 2025-11-11 09:06:37

#include <bits/stdc++.h>

using namespace std;

const int nx=105;

int n, m, t, mp[nx][nx], dx[]={1, 0, 0, -1}, dy[]={0, 1, -1, 0}, vs[nx][nx], cnt, i, j;
queue<pair<int, int>> q;

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>m>>t;
    for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) cin>>mp[i][j], cnt+=mp[i][j];
    while (t--)
    {
        cin>>i>>j;
        if (vs[i][j]||!mp[i][j]) 
        {
            cout<<cnt<<'\n';
            continue;
        }
        q.push({i, j});
        vs[i][j]=1;
        while (!q.empty())
        {
            auto [i, j]=q.front();
            q.pop();
            cnt--;
            for (int k=0; k<4; k++) if (mp[i+dx[k]][j+dy[k]]&&!vs[i+dx[k]][j+dy[k]]) vs[i+dx[k]][j+dy[k]]=1, q.push({i+dx[k], j+dy[k]}); 
        }
        cout<<cnt<<'\n';
    }
}