正文
增加 44 行删除 1 行
1,972 行未改动全部展开19731974197519761977197819791980198113 行未改动19951996199719981999200020012002206 行未改动全部展开1,972 行未改动全部展开```## 字符串### HASH```cppinline int f(int l, int r) {13 行未改动rep(i, 1, n) H[i] = H[i - 1] * base + s[i],}```### TRIE 字典树```cpp#include <iostream>206 行未改动全部展开1,972 行未改动全部展开19731974197519761977197819791980198113 行未改动199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045206 行未改动全部展开1,972 行未改动全部展开```## 字符串### 一维 HASH```cppinline int f(int l, int r) {13 行未改动rep(i, 1, n) H[i] = H[i - 1] * base + s[i],}```### 二维 HASH```cppstruct D_HASH {ull h[N][N];int n, m;inline ull ask(int x1, int y1, int x2, int y2) {if(x1 > x2 || y1 > y2) return 0;ull yb = b1[y2 - y1 + 1];ull xb = b2[x2 - x1 + 1];return h[x2][y2] - h[x2][y1 - 1] * yb - h[x1 - 1][y2] * xb + h[x1 - 1][y1 - 1] * xb * yb;}inline void INIT(const int a[][N], int nn, int mm) {n = nn, m = mm;rep(i, 1, n) {rep(j, 1, m) {h[i][j] = h[i][j - 1] * B1 + h[i - 1][j] * B2 - h[i - 1][j - 1] * B1 * B2 + a[i][j];}}}};``````cppstruct D_HASH {ull h[N][N];int n, m;inline ull ask(int x1, int y1, int x2, int y2) {if(x1 > x2 || y1 > y2) return 0;ull yb = b1[y2 - y1 + 1];ull xb = b2[x2 - x1 + 1];return h[x2][y2] - h[x2][y1 - 1] * yb - h[x1 - 1][y2] * xb + h[x1 - 1][y1 - 1] * xb * yb;}inline void INIT(const string *s, int nn, int mm) {n = nn, m = mm;rep(i, 1, n) {rep(j, 1, m) {h[i][j] = h[i][j - 1] * B1 + h[i - 1][j] * B2 - h[i - 1][j - 1] * B1 * B2 + s[i][j];}}}};```### TRIE 字典树```cpp#include <iostream>206 行未改动全部展开