SCL--字符串HASH

 22:13:59 2015-11-05

结构体 HASH,贴在这~

struct Hash{
  ll B,mod,len,Has[200005],Base[200005];
  void init(char *s,LL _len,LL _B,LL _mod){
    B=_B; mod=_mod; len=_len;
    Base[0]=1; Has[0]=0; 
    for (LL i=1;i<=len;i++){
      Base[i]=Base[i-1]*B%mod;
      Has[i]=(Has[i-1]*B+s[i-1]+1)%mod;
    }
    return;
  }
  ll gethash(ll l,ll r){
    return ((Has[r]-Has[l-1]*Base[r-l+1])%mod+mod)%mod;
  }
};

 

posted @ 2015-09-16 21:53  Naturain  阅读(393)  评论(0编辑  收藏  举报