正文
增加 20 行删除 7 行
12345693 行未改动100101102103104105106107108114 行未改动全部展开22322422522622722822923023123223323469 行未改动30430530630730830931031131297 行未改动4104114124134144154164174184194204215 行未改动42742842943043143243343443520 行未改动尝试写出最通俗的字符串学习笔记。## kmp>给定主串 $s$ 和模式串 $t$,求 $t$ 在 $s$ 中出现的位置和 $t$ 所有非空前缀的最长 border 长度。93 行未改动signed main(){ios::sync_with_stdio(0);cin.tie(0);// freopen("app.in","r",stdin);// freopen("app.out","w",stdout);cin >> s >> t;114 行未改动全部展开signed main(){ios::sync_with_stdio(0);cin.tie(0);// freopen("app.in","r",stdin);// freopen("app.out","w",stdout);cin >> s;n = s.size();for(int i = 0; i < n; i++){69 行未改动我们用一个 vector 套结构体,结构体里面开一个长度为 $26$ 的数组。设一个这个类型的变量 $t_{i,j}$ 表示编号为 $i$ 对应字符 $j$ 的儿子的编号。新塞进一个节点 $x$,我们设其父节点为 $fa$。如果 $t_{fa,x}=0$,则赋予 $x$ 新的编号 $\text{num}$,并令 $t_{fa,x}\gets\text{num}$。我们发现,并不一定字符串的结尾都是叶子结点(例如 $\texttt{abc}$ 和 $\texttt{abcde}$),所以我们再设一个数组 $\text{cnt}_x$ 表示以编号为$x$ 的结点结尾的字符串有多少个。至此其实已经毕业了。## fail 树(失配树)97 行未改动signed main(){ios::sync_with_stdio(0);cin.tie(0);// freopen("app.in","r",stdin);// freopen("app.out","w",stdout);cin >> s;n = s.size();s = "-" + s;5 行未改动break;}if(!nxt[i]) break;nxt[i] = nxt[nxt[i]];}}for(int i = 1; i <= n; i++){add(i+1,nxt[i]+1);20 行未改动1234567891011121314151617181993 行未改动113114115116117118119120121114 行未改动全部展开23623723823924024124224324424524624769 行未改动31731831932032132232332432597 行未改动4234244254264274284294304314324334345 行未改动44044144244344444544644744820 行未改动尝试写出最通俗的字符串学习笔记。## 哈希### 单哈希别急。```cppcout << (lint)1e9 + 123 << endl;cout << (lint)1e15 + 37 << endl;cout << 29*(1ll<<57) + 1 << endl;cout << __LONG_LONG_MAX__ << endl;```## kmp>给定主串 $s$ 和模式串 $t$,求 $t$ 在 $s$ 中出现的位置和 $t$ 所有非空前缀的最长 border 长度。93 行未改动signed main(){ios::sync_with_stdio(0);cin.tie(0);// freopen("app.in","r",stdin);// freopen("app.out","w",stdout);cin >> s >> t;114 行未改动全部展开signed main(){ios::sync_with_stdio(0);cin.tie(0);// freopen("app.in","r",stdin);// freopen("app.out","w",stdout);cin >> s;n = s.size();for(int i = 0; i < n; i++){69 行未改动我们用一个 vector 套结构体,结构体里面开一个长度为 $26$ 的数组。设一个这个类型的变量 $t_{i,j}$ 表示编号为 $i$ 对应字符 $j$ 的儿子的编号。新塞进一个节点 $x$,我们设其父节点为 $fa$。如果 $t_{fa,x}=0$,则赋予 $x$ 新的编号 $\text{num}$,并令 $t_{fa,x}\gets\text{num}$。我们发现,并不一定字符串的结尾都是叶子结点(例如 $\texttt{abc}$ 和 $\texttt{abcde}$),所以我们再设一个数组 $\text{cnt}_x$ 表示以编号为$x$ 的结点结尾的字符串有多少个。至此其实已经毕业了。## fail 树(失配树)97 行未改动signed main(){ios::sync_with_stdio(0);cin.tie(0);// freopen("app.in","r",stdin);// freopen("app.out","w",stdout);cin >> s;n = s.size();s = "-" + s;5 行未改动break;}if(!nxt[i]) break;nxt[i] = nxt[nxt[i]];}}for(int i = 1; i <= n; i++){add(i+1,nxt[i]+1);20 行未改动