Submission

Status:

[PPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: Saizon

Problemset: fireball

Language: cpp

Time: 0.005 second

Submitted On: 2026-10-29 21:52:05

/*#include<iostream>
#include<queue>
using namespace std;
int s[105][105];

int main(){
    int n, m, q;
    cin >> n >> m >> q;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin >> s[i][j];
        }
    }
    int p, o;
    int him;
    for(int i=1;i<=q;i++){
        him = 0;
        cin >> p >> o;
        bool b = false;
        for(int j=1;j<=n;j++){
            for(int l=1;l<=m;l++){
                if(s[j][l] == 1) him += 1;
                if(s[j][l] == 2){
                    s[j][l] = 0;
                }
            }
        }
        cout << him << "\n";
        s[p][o] = 2;
        while(true){
            for(int j=1;j<=n;j++){
                for(int l=1;l<=m;l++){
                    if(s[j][l] == 1){
                        if(s[j+1][l] == 2){
                            s[j][l] = 2;
                            b = true;
                        }
                        if(s[j][l+1] == 2){
                            s[j][l] = 2;
                            b = true;
                        }
                        if(s[j-1][l] == 2){
                            s[j][l] = 2;
                            b = true;
                        }
                        if(s[j][l-1] == 2){
                            s[j][l] = 2;
                            b = true;
                        }
                    }
                }
            }
            if(b == false) break;
        }
    }
}*/

#include<iostream>
#include<queue>
#include<utility>
using namespace std;
queue<pair<int, int>> q;
bool vis[105][105];
int s[105][105];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    int n, m, him;
    cin >> n >> m >> him;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin >> s[i][j];
        }
    }
    int p, o;
    for(int i=1;i<=him;i++){
        cin >> p >> o;
        if(s[p][o] == 1){
            q.push({p ,o});
            while(! q.empty()){
                int x = q.front().first;
                int y = q.front().second;
                //cout << x << ' ' << y << "\n";
                q.pop();
                s[x][y] = 0;
                for(int j=0;j<4;j++){
                    int xx = x + dx[j];
                    int yy = y + dy[j];
                    if(s[xx][yy] == 1 && vis[xx][yy] == false){
                        s[xx][yy] = 0;
                        vis[xx][yy] = true;
                        q.push({xx, yy});
                    }
                }
            }
        }
        int l = 0;
        for(int j=1;j<=n;j++){
            for(int u=1;u<=m;u++){
                if(s[j][u] == 1){
                    l ++;
                }
            }
        }
        cout << l << "\n";
    }
}