#include <cstdio>
#include <cstring>
#include <iostream>
#define oo 2139062143
#define fo(i,x,y) for (int i=(x);i<=(y);++i)
#define fd(i,x,y) for (int i=(x);i>=(y);--i)
using namespace std;
const int N=100100,M=50500,L=100100,C=13;
char s[L],t[L];
int n,m,l,ct;
int sa[N],rnk[N],w[N],se[N];
void gt_sa()
{
fo(i,0,ct) w[i]=0;
fo(i,1,n) ++w[rnk[i]];
fo(i,1,ct) w[i]+=w[i-1];
fd(i,n,1) sa[w[rnk[se[i]]]--]=se[i];
}
int same(int x,int y,int len)
{
return(se[x]==se[y]&&se[x+len]==se[y+len]);
}
int h[N],he[N];
void get_sa()
{
ct=11;rnk[n+1]=-1;
fo(i,1,n) se[i]=i,rnk[i]=s[i]-'a'+1;
gt_sa();
for(int len=1;len<=n;len<<=1)
{
int tct=0;
fo(i,n-len+1,n) se[++tct]=i;
fo(i,1,n) if(sa[i]>len) se[++tct]=sa[i]-len;
gt_sa();swap(rnk,se);rnk[sa[1]]=ct=1;
fo(i,2,n)
if(!same(sa[i-1],sa[i],len/**2*/))
rnk[sa[i]]=++ct;
else rnk[sa[i]]=ct;
}
fo(i,1,n)
{
h[i]=max(h[i-1]-1,0);
while(s[i+h[i]]==s[sa[rnk[i]-1]+h[i]]) ++h[i];
}
fo(i,1,n) he[i]=h[sa[i]];
}
int main()
{
// freopen("D:/LiuYuanHao/a.in","r",stdin);
// scanf("%d\n",&n);
scanf("%s\n",s+1);
get_sa();
fo(i,1,n) printf("%d ",sa[i]);
printf("\n");
fo(i,2,n) printf("%d ",he[i]);
/*
scanf("%d",&m);
while(m--)
{
scanf("%s\n",t+1);
}*/
return 0;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Subtask #1 Testcase #1 | 33.65 us | 56 KB | Wrong Answer | Score: 0 | 显示更多 |
| Subtask #1 Testcase #2 | 37.66 us | 56 KB | Wrong Answer | Score: 0 | 显示更多 |
| Subtask #1 Testcase #3 | 38.23 us | 56 KB | Wrong Answer | Score: 0 | 显示更多 |
| Subtask #1 Testcase #4 | 35.27 us | 56 KB | Wrong Answer | Score: 0 | 显示更多 |
| Subtask #1 Testcase #5 | 34.55 us | 56 KB | Wrong Answer | Score: 0 | 显示更多 |
| Subtask #1 Testcase #6 | 34.76 us | 56 KB | Wrong Answer | Score: 0 | 显示更多 |
| Subtask #1 Testcase #7 | 197.14 us | 148 KB | Wrong Answer | Score: 0 | 显示更多 |
| Subtask #1 Testcase #8 | 197.3 us | 148 KB | Wrong Answer | Score: 0 | 显示更多 |
| Subtask #1 Testcase #9 | 197.03 us | 148 KB | Wrong Answer | Score: 0 | 显示更多 |
| Subtask #1 Testcase #10 | 142.79 us | 120 KB | Wrong Answer | Score: 0 | 显示更多 |
| Subtask #1 Testcase #11 | 142 us | 120 KB | Wrong Answer | Score: 0 | 显示更多 |
| Subtask #1 Testcase #12 | 197.33 us | 148 KB | Wrong Answer | Score: 0 | 显示更多 |
| Subtask #1 Testcase #13 | 198.28 us | 148 KB | Wrong Answer | Score: 0 | 显示更多 |
| Subtask #1 Testcase #14 | 197.52 us | 148 KB | Wrong Answer | Score: 0 | 显示更多 |
| Subtask #1 Testcase #15 | 198.36 us | 148 KB | Wrong Answer | Score: 0 | 显示更多 |
| Subtask #1 Testcase #16 | 197.9 us | 148 KB | Wrong Answer | Score: 0 | 显示更多 |
| Subtask #1 Testcase #17 | 197.58 us | 148 KB | Wrong Answer | Score: 0 | 显示更多 |
| Subtask #1 Testcase #18 | 197.82 us | 148 KB | Wrong Answer | Score: 0 | 显示更多 |