Submission

Status:

[PPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: 12345678

Problemset: fireball

Language: cpp

Time: 0.003 second

Submitted On: 2025-11-29 15:31:11

#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n, m, q, count=0, coor_1, coor_2;
    cin >> n >> m >> q;
    int earth[n][m];
    for (int i=0; i<n; i++) {
        for (int j=0; j<m; j++) {
            cin >> earth[i][j];
            if (earth[i][j]==1) {
                count += 1;
            }
        }
    }
    for (int i=0; i<q; i++) {
        int x, y;
        cin >> x >> y;
        x = x - 1, y = y - 1;
        if (earth[x][y]==1) {
            count -= 1;
            earth[x][y] = 0;
            queue<pair<int,int>> book;
            book.push({x,y});
            while (book.size()>0) {
                coor_1 = book.front().first;
                coor_2 = book.front().second;
                book.pop();
                if (coor_1!=0) {
                    if (earth[coor_1-1][coor_2]==1) {
                        book.push({coor_1-1,coor_2});
                        earth[coor_1-1][coor_2]=0;
                        count -= 1;
                    }
                }
                if (coor_1!=n-1) {
                    if (earth[coor_1+1][coor_2]==1) {
                        book.push({coor_1+1,coor_2});
                        earth[coor_1+1][coor_2]=0;
                        count -= 1;
                    }
                }
                if (coor_2!=0) {
                    if (earth[coor_1][coor_2-1]==1) {
                        book.push({coor_1,coor_2-1});
                        earth[coor_1][coor_2-1]=0;
                        count -= 1;
                    }
                }
                if (coor_2!=m-1) {
                    if (earth[coor_1][coor_2+1]==1) {
                        book.push({coor_1,coor_2+1});
                        earth[coor_1][coor_2+1]=0;
                        count -= 1;
                    }
                }
            }
        }
        cout << count << "\n";
    }
}