运用STL自带的sort排序,双关键字压成一个long long,常数很小的 Nlog2N
//#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <limits>
#include <map>
#include <vector>
#include <queue>
#define LL long long
#define ft first
#define sd second
#define mp(x,y) make_pair(x,y)
#define db double
//#define int LL
using namespace std;
const int N = 2e6+233;
//const int mod = ;
const int INF =numeric_limits<int >::max();
#define rep(i,x,y) for (int i=x;i<=y;++i)
LL a[N];
int rk[N],sa[N];
#define tup(x,y,z) ((LL)x+1<<42|(LL)y+1<<21|(LL)z)
#define trd(x) (x&(1ll<<21)-1ll)
void SA(char *s,int n)
{
rep(i,1,n) sa[i]=s[i];
sort(sa+1,sa+n+1);
int m=unique(sa+1,sa+n+1)-sa;
rep(i,1,n) rk[i]=lower_bound(sa+1,sa+m,s[i])-sa;
rep(i,n+1,n<<1) rk[i]=-1;
for (int k=1;k<=n;k<<=1)
{
rep(i,1,n) a[i]=tup(rk[i],rk[i+k],i);
sort(a+1,a+1+n);
for (int j=0,i=1;i<=n;++i) rk[trd(a[i])]=a[i]>>21 >a[i-1]>>21 ? ++j:j;
}
rep(i,1,n) sa[rk[i]]=i;
}
int n;
char s[N];
signed main()
{
scanf("%s",s+1);
n=strlen(s+1);
SA(s,n);
rep(i,1,n) printf("%d ",sa[i]);
return 0;
}