解析:
二維哈希模板
Sp[b]-hip[a*b]+h[j]
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const int N=1e6+1000;
int n,m,a,b,q;
char str[20005];
ull h[3005][3005];
ull p[N];
ull P=131;
ull get(ull f[],int l,int r)
{
return f[r]-f[l-1]*p[r-l+1];
}
int main()
{
scanf("%d %d %d %d",&n,&m,&a,&b);
p[0]=1;
for(int i=1;i<=n*m;i++) p[i]=p[i-1]*P;
for(int i=1;i<=n;i++)
{
scanf("%s",(str+1));
for(int j=1;j<=m;j++) h[i][j]=h[i][j-1]*P+(str[j]-'0');
}
unordered_set<ull> S;
for(int i=b;i<=m;i++)
{
ull s=0;
int l=i-b+1,r=i;
for(int j=1;j<=n;j++)
{
s=s*p[b]+get(h[j],l,r);
if(j>a) s=s-get(h[j-a],l,r)*p[a*b];
if(j>=a) S.insert(s);
}
}
cin>>q;
while(q--)
{
ull s=0;
for(int i=1;i<=a;i++)
{
scanf("%s",(str+1));
for(int j=1;j<=b;j++)
{
s=s*P+(str[j]-'0');
}
}
if(S.count(s)) cout<<1<<endl;
else cout<<0<<endl;
}
}