#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define f first
#define s second
#define pb push_back
#define pp pop_back
string pr(int* vv,int l,int r){for(int i=l;i<r;i++)cout<<vv[i]<<" ";return"";}
const int L=1000+10;
int n,m,q;
bool ok[L][L],a[L][L];
int cnt[L*2];
void add(int x,int y){
if(!ok[x][y])
return;
cnt[x+y-1]--;
ok[x][y] = 0;
if(ok[x+1][y] and !ok[x+1][y-1])
add(x+1,y);
if(ok[x][y+1] and !ok[x-1][y+1])
add(x,y+1);
if(ok[x-1][y] and !ok[x-1][y+1])
add(x-1,y);
if(ok[x][y-1] and !ok[x+1][y-1])
add(x,y-1);
}
void prr(){
cout<<"cnt: "<<pr(cnt,1,n+m)<<endl;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cout<<ok[i][j];
}
cout<<endl;
}
cout<<"----------------"<<endl;
}
int main(){
//ifstream cin ("in.in");
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
ok[i][j] = 1;
cnt[i+j-1]++;
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];
if(a[i][j]){
add(i,j);
}
}
}
cin>>q;
for(int tt=1;tt<=q;tt++){
int x,y;
cin>>x>>y;
int ans = 0;
if(cnt[x+y-1] != 1 or !ok[x][y]){
ans = 1;
add(x,y);
}
cout<<ans<<'\n';
//prr();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |