. 1 #include <bits / STDC ++ H.>
2 #define Nmax of 1000010
. 3
. 4 the using namespace STD;
. 5 int C [Nmax of], RK [Nmax of], SA [Nmax of], X [Nmax of], Y [Nmax of];
. 6 / / Y [i] a second keyword ranking number i of the position of the first keyword
. 7
. 8 char S [Nmax of];
. 9 int n-, K, m = 200 is ;
10
. 11 void qsort () {
12 is for ( int i = . 1 ; I <= m; I ++) C [I] = 0 ;
13 is for ( int I = . 1; i<=n; i++) c[ x[i] ]++;
14 for (int i=1; i<=m; i++) c[i]+=c[i-1];
15 for (int i=n; i>=1; i--) sa[ c[ x[y[i]] ]-- ]=y[i];
16 }
17
18 int main(){
19 scanf("%s",s+1);
20 n=strlen(s+1);
21 for (int i=1; i<=n; i++) x[i]=s[i];
22 for (int I = . 1 ; I <= n-; I ++) Y [I] = I;
23 is qsort ();
24 for ( int L = . 1 ; L <n-; L << = . 1 ) {
25 int T = 0 ;
26 is for ( int I = n-L-+ . 1 ; I <= n-; I ++) Y [T ++] = I;
27 // some figures are not the first key, the second key is not sa some numbers [i ] can cover the range of
28 for ( int I = . 1 ; I <= n-; I ++) IF (SA [I]> L) Y [T ++] = SA [I] -l; // if there is a first keywords
29 qsort ();
30 m = . 1 ;
31 is Y [SA [ . 1 ]] = m;
32 for ( int I = 2 ; I <= n-; I ++ ) {
33 is // fallibility Here, sa [i] refer to the lengths 2l, but x refers to the length of only l, so also the second keyword comparison
34 is IF (x [SA [I]] == x [SA [I- . 1 ]]) IF (x [SA [I] + L] = X = [SA [I- . 1 ] + L]) {Y [SA [I]] = m; Continue ;}
35 Y [SA [I]] ++ = m;
36 }
37 [ for ( int I = . 1 ; I <= n-; I ++) X [I] = Y [I];
38 is }
39 for (int i=1; i<=n; i++) printf("%d ",sa[i]);
40 return 0;
41 }