Hash
哈希
省选前发现自己不会哈希,害怕
Rolling Hash
对于序列 \(a_i\),素数 \(M\)
\[\sum_{i=0}^{n-1}a_i x^i \mod M
\]
可以拓展,如果有一个关于值域的桶 \(b\)
\[\sum_i b_i x^i \mod M
\]
\[\sum_i b_i x^{-i} \mod M
\]
可以实现翻转
常用 \(x,M\)
| x | M |
|---|---|
| 131 | 998244353 |
| 13331 | 1000000007 |
Set Hash
对于集合 \(S\)
\[\prod_{s\in S}(x+s) \mod M
\]
Tree Hash
\(f_u\) 子树高度,素数 \(M\)
\[hash(u)=\prod(hash(v)+f_v) \mod M
\]

浙公网安备 33010602011771号