This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define MOD1 1000000007
#define MOD2 1000000013
using namespace std;
int n,m,i,j,k,t,q,x,y,val,val2;
int v[1005][1005],din[1005][1005],din2[1005][1005];
int main()
{
ios_base :: sync_with_stdio(false);
cin.tie(0);
#ifdef HOME
ifstream cin("date.in");
ofstream cout("date.out");
#endif // HOME
cin>>n>>m;
for (i=1; i<=n; i++)
{
for (j=1; j<=m; j++)
{
cin>>v[i][j];
}
}
din[1][1]=din2[1][1]=1;
for (i=1; i<=n; i++)
{
for (j=1; j<=m; j++)
{
din[i][j]=(din[i][j]+din[i-1][j]+din[i][j-1])%MOD1;
din2[i][j]=(din2[i][j]+din2[i-1][j]+din2[i][j-1])%MOD2;
}
}
for (i=1; i<=n; i++)
{
for (j=1; j<=m; j++)
{
if (v[i][j]==1)
{
val=din[i][j];
val2=din2[i][j];
for (k=i; k<=n; k++)
{
for (t=j; t<=m; t++)
{
din[k][t]=(din[k][t]-val+MOD1)%MOD1;
din2[k][t]=(din2[k][t]-val2+MOD2)%MOD2;
}
}
}
}
}
cin>>q;
for (i=1; i<=q; i++)
{
cin>>x>>y;
if (x==1&&y==1)
{
cout<<"0"<<'\n';
continue;
}
if ((din[n][m]-din[x][y]+MOD1)%MOD1!=0&&(din2[n][m]-din2[x][y]+MOD2)%MOD2!=0)
{
cout<<"1"<<'\n';
val=din[x][y];
val2=din2[x][y];
for (k=x; k<=n; k++)
{
for (t=y; t<=m; t++)
{
din[k][t]=(din[k][t]-val+MOD1)%MOD1;
din2[k][t]=(din2[k][t]-val2+MOD2)%MOD2;
}
}
}
else
{
cout<<"0"<<'\n';
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |