We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ce8fad6 commit eff8726Copy full SHA for eff8726
library/strings/suffix_array/suffix_array_short.hpp
@@ -7,11 +7,11 @@
7
//! vi s_vec;
8
//! auto [sa1, sa_inv1, lcp1] = sa_short(s_vec);
9
//! @endcode
10
-//! runs in ~0.5s for 5e5
+//! about 2-3x slower than KACTL
11
//! @time O(n * log^2(n))
12
//! @space O(n)
13
auto sa_short(const auto& s) {
14
- const int n = sz(s), b = 6;
+ int n = sz(s), b = 6;
15
vi sa(n), sa_inv(all(s)), lcp(n - 1);
16
iota(all(sa), 0);
17
for (int j = 1; j <= n; j *= b) {
@@ -24,7 +24,7 @@ auto sa_short(const auto& s) {
24
}
25
return false;
26
};
27
- sort(all(sa), cmp);
+ stable_sort(all(sa), cmp);
28
sa_inv[sa[0]] = 0;
29
rep(i, 1, n) sa_inv[sa[i]] =
30
sa_inv[sa[i - 1]] + cmp(sa[i - 1], sa[i]);
0 commit comments