Skip to content

Commit 76cc0f9

Browse files
authored
Fix suffix array index handling in LCP calculation
1 parent 9f834a9 commit 76cc0f9

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

library/strings/suffix_array/suffix_array_short.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ auto sa_short(const auto& s) {
2727
rep(i, 0, n - 1) {
2828
sa_inv[sa[i + 1]] = sa_inv[sa[i]];
2929
if (f(sa[i + 1]) != f(sa[i])) {
30-
sa_inv[sa[i]]++;
30+
sa_inv[sa[i + 1]]++;
3131
rep (k, 0, K) {
3232
if (f(sa[i + 1])[k] != f(sa[i])[k]) {
33-
lcp[i] = j * k + (i + j * k < n ? y[i + j * k] : 0);
33+
lcp[i] = j * k + (sa[i] + j * k < n ? y[sa_inv[sa[i] + j * k]] : 0);
3434
}
3535
}
3636
} else {

0 commit comments

Comments
 (0)