1#include"../../kyopro_library/template.hpp"
2#include"../../kyopro_library/others/xor128.hpp"
3#include"../../kyopro_library/others/modcal.hpp"
25 inv=vector<vector<ll>>(HASH_PRIME); pow=vector<vector<ll>>(HASH_PRIME);
28 pow[i][0]=1; inv[i][
HASH_MAX]=ModInv(ModPow<ll>(base[i],
HASH_MAX,mod[i]),mod[i]);
30 pow[i][j+1]=(pow[i][j]*base[i])%mod[i];
45 for(
int i=0; i<HASH_PRIME; i++) value[i]=num[c][i];
49 for(
int i=0; i<HASH_PRIME; i++) value[i]=(value[i]+other.value[i])%mod[i];
53 for(
int i=0; i<HASH_PRIME; i++) value[i]=(value[i]-other.value[i]+mod[i])%mod[i];
68 if(x<0)
for(
int i=0; i<
HASH_PRIME; i++) (ret.value[i]*=inv[i][-x])%=mod[i];
69 else for(
int i=0; i<
HASH_PRIME; i++) (ret.value[i]*=pow[i][x])%=mod[i];
73 for(
int i=0; i<
HASH_PRIME; i++)
if(value[i]!=other.value[i])
return false;
77 for(
int i=0; i<HASH_PRIME; i++) value[i]=other.value[i];
85const vector<
ll>
Hash::
mod={1000000007,1000000009,1000000021,1000000033,1000000087};
99 for(
int i=0; i<n; i++) hash[i+1]=hash[i]+Hash(s[i]).shift(i);
constexpr const int HASH_C
文字の範囲
constexpr const int HASH_PRIME
使う素数の個数
constexpr const int HASH_MAX
長さの最大値
bool operator==(const Hash &other) const
Hash operator+(const Hash &other) const
Hash operator-(const Hash &other) const
static vector< vector< ll > > pow
static vector< vector< ll > > inv
static const vector< ll > mod
Hash & operator+=(const Hash &other)
Hash & operator-=(const Hash &other)
Hash & operator=(const Hash &other)
static array< array< ll, HASH_PRIME >, 256 > num
Hash get(int l, int r)
区間 [l, r) のハッシュ値を取得する
RollingHash(const string &s)
文字列 s の Rolling Hash を構築する