#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
#define REP(i, a, b) for(int i = (a); i <= (b); ++ i)
#define PER(i, a, b) for(int i = (a); i >= (b); -- i)
int n;
char s[N];
namespace SA {
int Mem[N * 10], sa[N], H[N], rk[N];
void build(int m) {
int *x = Mem, *y = Mem + (N << 1), *z = y + (N << 1);
REP(i, 1, m) z[i] = 0;
REP(i, 1, n) ++ z[x[i] = s[i]];
REP(i, 1, m) z[i] += z[i - 1];
REP(i, 1, n) sa[z[x[i]] --] = i;
for(int k = 1; k <= n; k <<= 1) {
int p = 0;
REP(i, n - k + 1, n) y[++ p] = i;
REP(i, 1, n) if(sa[i] > k) y[++ p] = sa[i] - k;
REP(i, 1, m) z[i] = 0;
REP(i, 1, n) ++ z[x[i]];
REP(i, 1, m) z[i] += z[i - 1];
PER(i, n, 1) sa[z[x[y[i]]] --] = y[i];
swap(x, y); p = 0;
REP(i, 1, n) x[sa[i]] = (y[sa[i]] == y[sa[i - 1]] && y[sa[i] + k] == y[sa[i - 1] + k]) ? p : ++ p;
if(p == n) break;
m = p;
}
}
void getheight() {
int Now = 0;
REP(i, 1, n) rk[sa[i]] = i;
REP(i, 1, n) {
if(Now) -- Now;
if(rk[i] == n) continue;
while(s[i + Now] == s[sa[rk[i] + 1] + Now]) ++ Now;
H[rk[i]] = Now;
}
}
}
int main() {
scanf("%s", s + 1); n = strlen(s + 1);
SA :: build('z');
SA :: getheight();
REP(i, 1, n) printf("%d ", SA :: sa[i]); puts("");
REP(i, 1, n - 1) printf("%d ", SA :: H[i]); puts("");
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Subtask #1 Testcase #1 | 36.72 us | 60 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #2 | 45.31 us | 64 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #3 | 44.43 us | 64 KB | Accepted | Score: 100 | 显示更多 |
Subtask #1 Testcase #4 | 43.79 us | 64 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #5 | 42.2 us | 64 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #6 | 41.93 us | 64 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #7 | 30.061 ms | 3 MB + 160 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #8 | 45.818 ms | 3 MB + 380 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #9 | 32.111 ms | 3 MB + 252 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #10 | 20.819 ms | 2 MB + 140 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #11 | 21.492 ms | 2 MB + 180 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #12 | 37.027 ms | 3 MB + 444 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #13 | 35.915 ms | 3 MB + 464 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #14 | 33.369 ms | 3 MB + 276 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #15 | 33.021 ms | 3 MB + 280 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #16 | 35.709 ms | 3 MB + 444 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #17 | 35.632 ms | 3 MB + 444 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #18 | 35.902 ms | 3 MB + 444 KB | Accepted | Score: 0 | 显示更多 |