字符串哈希值的构造

 
#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; }
 
                    
                     
                    
                 
                    
                
 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号