Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions atcoder/string.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import copy
import functools
import typing

Expand All @@ -11,7 +10,7 @@ def _sa_naive(s: typing.List[int]) -> typing.List[int]:
def _sa_doubling(s: typing.List[int]) -> typing.List[int]:
n = len(s)
sa = list(range(n))
rnk = copy.deepcopy(s)
rnk = s.copy()
tmp = [0] * n
k = 1
while k < n:
Expand Down Expand Up @@ -75,14 +74,14 @@ def induce(lms: typing.List[int]) -> None:
nonlocal sa
sa = [-1] * n

buf = copy.deepcopy(sum_s)
buf = sum_s.copy()
for d in lms:
if d == n:
continue
sa[buf[s[d]]] = d
buf[s[d]] += 1

buf = copy.deepcopy(sum_l)
buf = sum_l.copy()
sa[buf[s[n - 1]]] = n - 1
buf[s[n - 1]] += 1
for i in range(n):
Expand All @@ -91,7 +90,7 @@ def induce(lms: typing.List[int]) -> None:
sa[buf[s[v - 1]]] = v - 1
buf[s[v - 1]] += 1

buf = copy.deepcopy(sum_l)
buf = sum_l.copy()
for i in range(n - 1, -1, -1):
v = sa[i]
if v >= 1 and ls[v - 1]:
Expand Down Expand Up @@ -160,7 +159,6 @@ def suffix_array(s: typing.Union[str, typing.List[int]],
upper: typing.Optional[int] = None) -> typing.List[int]:
'''
SA-IS, linear-time suffix array construction

Reference:
G. Nong, S. Zhang, and W. H. Chan,
Two Efficient Algorithms for Linear Time Suffix Array Construction
Expand Down Expand Up @@ -195,7 +193,6 @@ def lcp_array(s: typing.Union[str, typing.List[int]],
sa: typing.List[int]) -> typing.List[int]:
'''
Longest-Common-Prefix computation

Reference:
T. Kasai, G. Lee, H. Arimura, S. Arikawa, and K. Park,
Linear-Time Longest-Common-Prefix Computation in Suffix Arrays and Its
Expand Down Expand Up @@ -232,7 +229,6 @@ def lcp_array(s: typing.Union[str, typing.List[int]],
def z_algorithm(s: typing.Union[str, typing.List[int]]) -> typing.List[int]:
'''
Z algorithm

Reference:
D. Gusfield,
Algorithms on Strings, Trees, and Sequences: Computer Science and
Expand Down