​http://www.elijahqi.win/archives/2849​​​
Description

给定一个M行N列的01矩阵,以及Q个A行B列的01矩阵,你需要求出这Q个矩阵哪些在原矩阵中出现过。
所谓01矩阵,就是矩阵中所有元素不是0就是1。

Input

输入文件的第一行为M、N、A、B,参见题目描述。
接下来M行,每行N个字符,非0即1,描述原矩阵。
接下来一行为你要处理的询问数Q。
接下来Q个矩阵,一共Q*A行,每行B个字符,描述Q个01矩阵。

Output

你需要输出Q行,每行为0或者1,表示这个矩阵是否出现过,0表示没有出现过,1表示出现过。

Sample Input

3 3 2 2
111
000
111
3
11
00
11
11
00
11
Sample Output

1
0
1
HINT

对于100%的实际测试数据,M、N ≤ 1000,Q = 1000

对于40%的数据,A = 1。

对于80%的数据,A ≤ 10。

对于100%的数据,A ≤ 100。

裸的二维hash 预处理所有可能的hash值 到时候检查的时候判断即可

#include<map>
#include<cstdio>
#include<cctype>
#include<algorithm>
#define g1 3
#define g2 1311
#define N 1100
#define ll unsigned long long
using namespace std;
map<ll,int> mm;
inline char gc(){
static char now[1<<16],*S,*T;
if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
return *S++;
}
inline int read(){
int x=0,f=1;char ch=gc();
while(!isdigit(ch)) {if (ch=='-') f=-1;ch=gc();}
while(isdigit(ch)) x=x*10+ch-'0',ch=gc();
return x*f;
}
ll hs[N][N],p1[N],p2[N];
int m,n,a,b;
int main(){
freopen("bzoj2351.in","r",stdin);
m=read();n=read();a=read();b=read();
for (int i=1;i<=m;++i){char ch=gc();while(!isdigit(ch)) ch=gc();
for (int j=1;j<=n;++j) hs[i][j]=hs[i][j-1]*g1+(ch-'0'),ch=gc();
for (int j=1;j<=n;++j) hs[i][j]+=hs[i-1][j]*g2;
}p1[0]=1;p2[0]=1;
for (int i=1;i<=n;++i) p1[i]=p1[i-1]*g1;
for (int i=1;i<=m;++i) p2[i]=p2[i-1]*g2;
for (int i=a;i<=m;++i){
for (int j=b;j<=n;++j){
ll tmp=hs[i][j]+hs[i-a][j-b]*p2[a]*p1[b];
tmp-=hs[i-a][j]*p2[a]+hs[i][j-b]*p1[b];mm[tmp]=1;
}
}int Q=read();
while(Q--){
ll tmp=0;
for (int i=1;i<=a;++i) {char ch=gc();while(!isdigit(ch)) ch=gc();
for (int j=1;j<=b;++j)
tmp+=p2[a-i]*p1[b-j]*(ch-'0'),ch=gc();
}
if(mm[tmp]) puts("1");else puts("0");
}
return 0;
}