Matrix[矩阵hash]_#include

Matrix[矩阵hash]_#include_02 


 

#include<bits/stdc++.h>
#define N 1050
#define T 105
#define ULL unsigned long long
using namespace std;
int a[N][N],n,m,A,B,q;
ULL hash[N][N] , base[T*T];
map<ULL,int> M;
int main(){
scanf("%d%d%d%d",&n,&m,&A,&B);
base[0]=1;
for(int i=1;i<=A;i++) base[i] = base[i-1] * 31;
for(int i=1;i<=n;i++){
char s[N]; scanf("%s",s);
for(int j=1;j<=m;j++){
a[i][j] = s[j-1] - '0';
hash[i][j] = hash[i][j-1] * 31 + a[i][j];
}
}
for(int i=1;i<=n-A+1;i++){
for(int j=1;j<=m-B+1;j++){
ULL Hash=0;
for(int k=i;k<=A+i-1;k++){
Hash = (Hash + hash[k][j+B-1] - hash[k][j-1] * base[j]) * base[A];
}
M[Hash]++;
}
}
scanf("%d",&q); while(q--){
ULL Hash=0;
for(int i=1;i<=A;i++){
char s[N]; scanf("%s",s);
for(int j=1;j<=B;j++){
Hash = (Hash + (s[j-1]-'0')) * 31;
}
}
if(M[Hash*31]) printf("1\n");
else printf("0\n");
}return 0;
}