//#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <limits>
#include <map>
#include <vector>
#include <queue>
#define P pair<int ,int >
#define pb push_back
#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 = 1e5+233;
//const int mod = ;
const int INF =numeric_limits<int >::max();
#define rep(i,x,y) for (int i=x;i<=y;++i)
void read(int &x)
{
x=0;
char ch=getchar();
int f=1;
while (!isdigit(ch)) (ch=='-'?f=-1:0),ch=getchar();
while ( isdigit(ch)) x=x*10+ch-'0',ch=getchar();
x*=f;
}
struct suffix_array
{
static const int M=256;
int n,m,p,i,j,k,rk[N<<1],tp[N<<1],cnt[N<<1],sa[N],h[N];
int *x=rk,*y=tp;
char str[N<<1];
void Sort()
{
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[w+x]==f[w+y];}
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;
for (k=0,j,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()
{
scanf("%s",S.str+1);
S.n=strlen(S.str+1);
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 | 37.85 us | 64 KB | Wrong Answer | Score: -100 | 显示更多 |
| Subtask #1 Testcase #2 | 47.78 us | 64 KB | Accepted | Score: 100 | 显示更多 |
| Subtask #1 Testcase #3 | 46.56 us | 64 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #4 | 43.37 us | 64 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #5 | 43.08 us | 64 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #6 | 43.23 us | 64 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #7 | 53.319 ms | 2 MB + 820 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #8 | 50.823 ms | 2 MB + 1008 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #9 | 52.948 ms | 2 MB + 872 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #10 | 33.231 ms | 1 MB + 904 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #11 | 32.707 ms | 1 MB + 944 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #12 | 38.959 ms | 3 MB + 40 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #13 | 38.96 ms | 3 MB + 144 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #14 | 51.272 ms | 2 MB + 900 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #15 | 50.6 ms | 2 MB + 916 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #16 | 38.755 ms | 3 MB + 40 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #17 | 38.719 ms | 3 MB + 40 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #18 | 39.164 ms | 3 MB + 40 KB | Accepted | Score: 0 | 显示更多 |