字符串哈希值的构造
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<bits/stdc++.h> using namespace std; #define pb push_back typedef long long ll; typedef unsigned long long ull; const int M=1e5+5; const int P=131; ull p[M],h[M]; ull get(int l,int r){///计算子串h[l~r]的哈希值 return h[r] - h[l - 1] * p[r - l + 1]; } int main(){ int n,m; scanf("%d%d",&n,&m); p[0]=1; for(int x,i=1;i<=n;i++){ scanf("%d",&x); p[i]=p[i-1]*P; h[i]=h[i-1]*P+x+1; } return 0; }