#include <bits/stdc++.h>
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#ifdef WA_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
using ll = long long;
using ull = unsigned long long;
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=int(a);i<=(int)(b);i++)
#define per(i,a,b) for(int i=int(a);i>=(int)(b);i--)
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5+10;
const int maxbit=19;
struct SuffixArray
{
// sa: 排名为i的后缀位置
// rank:位置为i的排名
int sa[maxn], rank[maxn], ws[maxn], wv[maxn], wa[maxn], wb[maxn], height[maxn], st[maxbit][maxn], N;
bool cmp(int *r, int a, int b, int l){return r[a]==r[b] and r[a+l]==r[b+l];}
void build(int *r, int n, int m)
{
N=n;
n++;
int i, j, k=0, p, *x=wa, *y=wb, *t;
for(i=0;i<m;i++)ws[i]=0;
for(i=0;i<n;i++)ws[x[i]=r[i]]++;
for(i=1;i<m;i++)ws[i]+=ws[i-1];
for(i=n-1;i>=0;i--)sa[--ws[x[i]]]=i;
for(p=j=1;p<n;j<<=1,m=p)
{
for(p=0,i=n-j;i<n;i++)y[p++]=i;
for(i=0;i<n;i++)if(sa[i]>=j)y[p++]=sa[i]-j;
for(i=0;i<n;i++)wv[i]=x[y[i]];
for(i=0;i<m;i++)ws[i]=0;
for(i=0;i<n;i++)ws[wv[i]]++;
for(i=1;i<m;i++)ws[i]+=ws[i-1];
for(i=n-1;i>=0;i--)sa[--ws[wv[i]]]=y[i];
for(t=x,x=y,y=t,p=1,i=1,x[sa[0]]=0;i<n;i++)
x[sa[i]]=cmp(y,sa[i-1],sa[i],j)?p-1:p++;
}
for(i=0;i<n;i++)rank[sa[i]]=i;
for(i=0;i<n-1;height[rank[i++]]=k)
for(k?k--:0,j=sa[rank[i]-1];r[i+k]==r[j+k];k++);
}
void build_st() //st表
{
int i, k;
for(i=1;i<=N;i++)st[0][i]=height[i];
for(k=1;k<=maxbit;k++)
for(i=1;i+(1<<k)-1<=N;i++)
st[k][i]=min(st[k-1][i],st[k-1][i+(1<<k-1)]);
}
int lcp(int x, int y) //最长公共前缀
{
int l=rank[x], r=rank[y];
if(l>r)swap(l,r);
if(l==r)return N-sa[l];
int t=log2(r-l);
return min(st[t][l+1],st[t][r-(1<<t)+1]);
}
}SA;
int ch[maxn];
int main() {
#ifndef WA_DEBUG
ios::sync_with_stdio(false);cin.tie(nullptr);
#endif
string s;
cin>>s;
int n=s.size();
rep(i,0,n-1) {
ch[i]=s[i];
}
ch[n]=0;
SA.build(ch,n,200);
rep(i,1,n) {
cout<<SA.sa[i]+1<<' ';
}
cout<<'\n';
rep(i,2,n) {
cout<<SA.height[i]<<' ';
}
cout<<'\n';
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Subtask #1 Testcase #1 | 43.71 us | 96 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #2 | 47.48 us | 96 KB | Accepted | Score: 100 | 显示更多 |
Subtask #1 Testcase #3 | 46.84 us | 96 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #4 | 48.99 us | 108 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #5 | 47.25 us | 108 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #6 | 48.26 us | 108 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #7 | 20.397 ms | 4 MB + 64 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #8 | 36.184 ms | 4 MB + 284 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #9 | 22.388 ms | 4 MB + 148 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #10 | 14.459 ms | 2 MB + 816 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #11 | 15.256 ms | 2 MB + 856 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #12 | 27.723 ms | 4 MB + 348 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #13 | 26.484 ms | 4 MB + 368 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #14 | 23.734 ms | 4 MB + 176 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #15 | 23.443 ms | 4 MB + 184 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #16 | 27.833 ms | 4 MB + 348 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #17 | 27.929 ms | 4 MB + 348 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #18 | 28.326 ms | 4 MB + 348 KB | Accepted | Score: 0 | 显示更多 |