版本比较
字符串哈希和碰撞概率
正文
增加 8 行删除 4 行
40 行未改动41424344454647484950515253545556575859606151 行未改动40 行未改动## 双哈希带质数模数(快速计算子串哈希值)```cppconst int B[2] = {233, 131}, MOD[2] = {998244353, (int)1e9 + 7};const int K = 2;using H = array<int, K>;struct Hash {int n;vector<H> b; // 进制基数的 i 次方vector<H> pre; // 前缀哈希值void init(const string &s) {this->n = s.size();b.resize(n + 1);pre.resize(n + 1);for (int i = 0; i < n; i++) {for (int x = 0; x < K; x++) {b[i + 1][x] = 1ll * b[i][x] * B[x] % MOD[x];pre[i + 1][x] = (1ll * pre[i][x] * B[x] + s[i]) % MOD[x];51 行未改动40 行未改动4142434445464748495051525354555657585960616263646551 行未改动40 行未改动## 双哈希带质数模数(快速计算子串哈希值)```cpp#include <bits/stdc++.h>using namespace std;const int K = 2;using H = array<int, K>;const H B = {233, 131}, MOD = {998244353, (int)1e9 + 7};struct Hash {int n;vector<H> b; // 进制基数的 i 次方vector<H> pre; // 前缀哈希值void init(const string &s) {this->n = s.size();b.assign(n + 1, H{});pre.assign(n + 1, H{});b[0].fill(1);for (int i = 0; i < n; i++) {for (int x = 0; x < K; x++) {b[i + 1][x] = 1ll * b[i][x] * B[x] % MOD[x];pre[i + 1][x] = (1ll * pre[i][x] * B[x] + s[i]) % MOD[x];51 行未改动