-
Notifications
You must be signed in to change notification settings - Fork 18
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
14 changed files
with
71 additions
and
128 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,50 @@ | ||
/** 马拉车(Manacher, with string) | ||
* 2024-04-06: https://qoj.ac/submission/380047 | ||
* 2024-04-09: https://qoj.ac/submission/384389 【模板】 | ||
**/ | ||
std::vector<int> manacher(std::string s) { | ||
std::string t = "#"; | ||
for (auto c : s) { | ||
t += c; | ||
t += '#'; | ||
} | ||
int n = t.size(); | ||
std::vector<int> r(n); | ||
for (int i = 0, j = 0; i < n; i++) { | ||
if (2 * j - i >= 0 && j + r[j] > i) { | ||
r[i] = std::min(r[2 * j - i], j + r[j] - i); | ||
} | ||
while (i - r[i] >= 0 && i + r[i] < n && t[i - r[i]] == t[i + r[i]]) { | ||
r[i] += 1; | ||
} | ||
if (i + r[i] > j + r[j]) { | ||
j = i; | ||
} | ||
} | ||
return r; | ||
} | ||
|
||
/** 马拉车(Manacher, with vector) | ||
* 2024-04-14: https://atcoder.jp/contests/abc349/submissions/52365777 | ||
**/ | ||
std::vector<int> manacher(std::vector<int> s) { | ||
std::vector<int> t{0}; | ||
for (auto c : s) { | ||
t.push_back(c); | ||
t.push_back(0); | ||
} | ||
int n = t.size(); | ||
std::vector<int> r(n); | ||
for (int i = 0, j = 0; i < n; i++) { | ||
if (2 * j - i >= 0 && j + r[j] > i) { | ||
r[i] = std::min(r[2 * j - i], j + r[j] - i); | ||
} | ||
while (i - r[i] >= 0 && i + r[i] < n && t[i - r[i]] == t[i + r[i]]) { | ||
r[i] += 1; | ||
} | ||
if (i + r[i] > j + r[j]) { | ||
j = i; | ||
} | ||
} | ||
return r; | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -16,5 +16,4 @@ std::vector<int> Z(std::string s) { | |
} | ||
} | ||
return z; | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -49,5 +49,4 @@ struct SuffixArray { | |
} | ||
} | ||
} | ||
}; | ||
|
||
}; |
3 changes: 3 additions & 0 deletions
3
03 - jiangly模板收集/05 - 字符串/04A - 后缀自动机(SuffixAutomaton 旧版).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
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 |
---|---|---|
|
@@ -74,5 +74,4 @@ struct SAM { | |
int size() { | ||
return t.size(); | ||
} | ||
}; | ||
|
||
}; |
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
File renamed without changes.
This file was deleted.
Oops, something went wrong.
File renamed without changes.