字符串哈希值的构造

#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;
}
View Code

 

posted @ 2020-07-14 23:51  starve_to_death  阅读(103)  评论(0编辑  收藏  举报