Hash
zhuyuhao1123 · · 算法·理论
#include<bits/stdc++.h>
#define N 2000001
using namespace std;
const int b=161;
typedef unsigned long long ull;
ull power[N],sum[N];
char s[N];
int len;
ull hash(int x,int y)
{
return sum[y]-sum[x-1]*power[y-x+1];
}
int main()
{
power[0]=1;
for(int i=1;i<N;++i) power[i]=power[i-1]*b;
cin>>s+1;
int len=strlen(s+1);
for(int i=1;i<=len;++i) sum[i]=sum[i-1]*b+s[i];
return 0;
}