forked from kth-competitive-programming/kactl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
127 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Author: adamant | ||
* Date: 2024-10-24 | ||
* License: CC0 | ||
* Source: https://codeforces.com/blog/entry/13959 | ||
* Description: Builds palindromic tree for a string. | ||
* Status: stress-tested | ||
*/ | ||
|
||
const int N = 1e5, sigma = 26; | ||
int s[N], len[N], link[N], to[N][sigma], n, last, sz; | ||
void init() {s[n++] = -1; link[0] = 1; len[1] = -1; sz = 2;} | ||
int get_link(int v) { | ||
while (s[n - len[v] - 2] != s[n - 1]) v = link[v]; | ||
return v; | ||
} | ||
void add_letter(int c) { | ||
s[n++] = c; last = get_link(last); | ||
if (!to[last][c]) { | ||
len[sz] = len[last] + 2; | ||
link[sz] = to[get_link(link[last])][c]; | ||
to[last][c] = sz++; | ||
} | ||
last = to[last][c]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Author: minhnhatnoe | ||
* Date: 2022-11-12 | ||
* License: CC0 | ||
* Source: minhnhatnoe and tuanlinh123 | ||
* Description: Suffix Automaton, supporting multiple strings. | ||
* The beginning iterator is $0$. Make calls to itmove to progress iterator. | ||
* Time: O(n) | ||
* Status: stress-tested | ||
*/ | ||
|
||
struct SuffixAutomaton{ | ||
struct Node{ | ||
int len, link = -1, nxt[26]; | ||
Node(int len): len(len) {fill(nxt, nxt + 26, -1);} | ||
Node(int len, int link, int _nxt[26]): | ||
len(len), link(link) {memcpy(nxt, _nxt, sizeof nxt);} | ||
}; | ||
vector<Node> g = {0}; | ||
int ptrans(int p, char c, int nxt) { | ||
for (int q = g[p].nxt[c]; p != -1 && g[p].nxt[c] == q; | ||
p = g[p].link) g[p].nxt[c] = nxt; | ||
return p; | ||
} | ||
int fbuild(int p, char c) { | ||
if (p == -1) return 0; | ||
int q = g[p].nxt[c]; | ||
if (g[p].len + 1 == g[q].len) return q; | ||
int qc = g.size(); | ||
g.emplace_back(g[p].len+1, g[q].link, g[q].nxt); | ||
ptrans(p, c, qc); return g[q].link = qc; | ||
} | ||
int addc(int p, char c) { // Progress iterator | ||
if (g[p].nxt[c] != -1) return fbuild(p, c); | ||
int nc = g.size(); | ||
g.emplace_back(g[p].len+1); | ||
int r = fbuild(ptrans(p, c, nc), c); | ||
g[nc].link = r; return nc; | ||
} | ||
}; |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion
2
stress-tests/number-theory/ModMulLL.cpp → stress-tests/number-theory/ModMul.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters