数hash:
hash 可以对质数取模来将一系列较大的数映射到质数那莫大的数组中,但因为可能会出现hash冲突可以用双模法降低hash冲突
or 用拉链法:
用vector存取模后的数,查找时现将数取模,找到对应的vector,然后遍历查找
字符串hash:(自己打的有可能错哦)
131进制,或13331进制
unsigned long long f[N],p[N];
char s[N];
int get(int l,int r)
{
return f[r]-f[l-1]*p[r-l+1];
}
int main(){
scanf("%s",s+1);
int len=strlen(s+1);
p[0]=1//131^0
for(int i=1;i<=n;i++){
f[i]=f[i-1]*131+s[i]-'a'+1;
p[i]=p[i-1]*131;
}
}