//include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define rep(i,x,y) for (int i=x;i<=y;++i)
using namespace std;
const int N = 2e5+233;
//const int mod = ;
struct Suffix_Array
{
static const int M=300;
int cnt[M],rk[N<<1],sa[N<<1],h[N<<1],n,m,p,i,j,k,tp[N<<1];
int *x=rk,*y=tp;
char str[N<<1];
inline void Init()
{
scanf("%s",str+1);
n=strlen(str+1);
}
void Sort()
{
//memset(cnt,0,sizeof(cnt)) ;
rep(i,0,m) cnt[i]=0;
rep(i,1,n) ++cnt[x[y[i]]];
rep(i,1,m) cnt[i]+=cnt[i-1];
for (int i=n;i>=1;--i)sa[ cnt[x[y[i]]]--] =y[i];
}
int cmp(int *f,int x,int y,int w){return f[x]==f[y]&&f[x+w]==f[y+w];}
void SA()
{
rep(i,1,n) x[i]=str[i],y[i]=i;
m=256;Sort();
for (int w=1;w<=n;w<<=1,m=p)
{
p=0;
rep(i,n-w+1,n) y[++p]=i;
rep(i,1,n) if (sa[i]>w) y[++p]=sa[i]-w;
Sort();
swap(x,y);
x[sa[1]]=p=1;
rep(i,2,n)
x[sa[i]]=cmp(y,sa[i],sa[i-1],w) ?p :++p;
}
rep(i,1,n) rk[sa[i]]=i;
int j,k=0;
for (int i=1;i<=n;h[rk[i++]]=k)
for (k ? --k :0,j=sa[rk[i] -1]; str[j+k]==str[i+k];++k);
}
}S;
signed main()
{
S.Init();
S.SA() ;
rep(i,1,S.n) printf("%d ",S.sa[i]);puts("");
rep(i,2,S.n) printf("%d ",S.h[i]) ;
return 0;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Subtask #1 Testcase #1 | 11.89 us | 36 KB | Wrong Answer | Score: 0 | 显示更多 |
| Subtask #1 Testcase #2 | 15.68 us | 36 KB | Accepted | Score: 100 | 显示更多 |
| Subtask #1 Testcase #3 | 14.54 us | 36 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #4 | 17.19 us | 36 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #5 | 16.77 us | 36 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #6 | 17.76 us | 36 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #7 | 194.798 ms | 1 MB + 444 KB | Runtime Error | Score: -100 | 显示更多 |
| Subtask #1 Testcase #8 | 192.671 ms | 1 MB + 380 KB | Runtime Error | Score: 0 | 显示更多 |
| Subtask #1 Testcase #9 | 193.207 ms | 1 MB + 448 KB | Runtime Error | Score: 0 | 显示更多 |
| Subtask #1 Testcase #10 | 186.461 ms | 964 KB | Runtime Error | Score: 0 | 显示更多 |
| Subtask #1 Testcase #11 | 186.398 ms | 964 KB | Runtime Error | Score: 0 | 显示更多 |
| Subtask #1 Testcase #12 | 183.386 ms | 1 MB + 384 KB | Runtime Error | Score: 0 | 显示更多 |
| Subtask #1 Testcase #13 | 184.901 ms | 1 MB + 324 KB | Runtime Error | Score: 0 | 显示更多 |
| Subtask #1 Testcase #14 | 193.75 ms | 1 MB + 364 KB | Runtime Error | Score: 0 | 显示更多 |
| Subtask #1 Testcase #15 | 191.069 ms | 1 MB + 428 KB | Runtime Error | Score: 0 | 显示更多 |
| Subtask #1 Testcase #16 | 184.207 ms | 1 MB + 312 KB | Runtime Error | Score: 0 | 显示更多 |
| Subtask #1 Testcase #17 | 184.696 ms | 1 MB + 368 KB | Runtime Error | Score: 0 | 显示更多 |
| Subtask #1 Testcase #18 | 185.157 ms | 1 MB + 368 KB | Runtime Error | Score: 0 | 显示更多 |