MCPcopy Create free account
hub / github.com/Jonathan-Uy/CSES-Solutions / extend

Function extend

String Algorithms/Substring Distribution.cpp:17–44  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15ll ans[maxN];
16
17void extend(char c){
18 int cur = sz++;
19 node[cur].len = node[last].len + 1;
20 int p = last;
21 while(p != -1 && !node[p].nxt.count(c)){
22 node[p].nxt[c] = cur;
23 p = node[p].link;
24 }
25 if(p == -1){
26 node[cur].link = 0;
27 } else {
28 int q = node[p].nxt[c];
29 if(node[p].len + 1 == node[q].len){
30 node[cur].link = q;
31 } else {
32 int clone = sz++;
33 node[clone].len = node[p].len + 1;
34 node[clone].nxt = node[q].nxt;
35 node[clone].link = node[q].link;
36 while(p != -1 && node[p].nxt[c] == q){
37 node[p].nxt[c] = clone;
38 p = node[p].link;
39 }
40 node[q].link = node[cur].link = clone;
41 }
42 }
43 last = cur;
44}
45
46void init(){
47 node[0].len = 0;

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected