二维哈希
cpp
ULL B1=131,B2=13331,pw1[N],pw2[N];
ULL getHash(int x1,int y1,int x2,int y2,vector<vector<ULL>>&h){
return h[x2][y2]-h[x2][y1-1]*pw2[y2-y1+1]-h[x1-1][y2]*pw1[x2-x1+1]+h[x1-1][y1-1]*pw1[x2-x1+1]*pw2[y2-y1+1];
}
void init(){
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
char c;
cin>>c;
h[i][j]=h[i-1][j]*B1+h[i][j-1]*B2-h[i-1][j-1]*B1*B2+c;
}
}
}