#include <iostream>
using namespace std;
int n,m;
int v[1001][1001];
int diag[2002];
bool in(int l,int c){
return (l>0 && c>0 && l<=n && c<=m);
}
void update(int l,int c);
void dfs(int l,int c){
if(!v[l+1][c-1]) {
update(l,c-1);
update(l+1,c);
}
if(!v[l-1][c+1]) {
update(l,c+1);
update(l-1,c);
}
}
void update(int l,int c){
///cout<<l<<" "<<c<<"|";
if(v[l][c]){
diag[l+c]--;v[l][c]=0;
dfs(l,c);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int i,j,a,b,q;
cin>>n>>m;
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
v[i][j]=1;diag[i+j]++;
}
}
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
cin>>a;
if(a) update(i,j);
}
}
cin>>q;
for(i=1;i<=q;i++){
cin>>a>>b;
if(v[a][b]==0){
cout<<"1\n";
}else if(diag[a+b]==1){
cout<<"0\n";
}else{
update(a,b);
cout<<"1\n";
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |