提交记录 21488
提交时间 |
评测时间 |
2024-04-11 23:10:48 |
2024-04-11 23:10:53 |
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
const int NN=(N<<1)+5;
int n,m=127;
int rk[NN];
int oldrk[NN];
int sa[N];
int id[N];
int cnt[N];
int height[N];
int key[N];
int main()
{
cin.tie(0)->sync_with_stdio(false);
cout.tie(0)->sync_with_stdio(false);
string s;
cin>>s;
n=s.size();
s=" "+s;
int p=0;
for(int i=1;i<=n;i++)cnt[rk[i]=s[i]]++;
for(int i=1;i<=m;i++)cnt[i]+=cnt[i-1];
for(int i=n;i>=1;i--)sa[cnt[rk[i]]--]=i;
for(int i=1;i<=n;i++)oldrk[i]=rk[i];
for(int i=1;i<=n;i++)
{
if(oldrk[sa[i]]!=oldrk[sa[i-1]])p++;
rk[sa[i]]=p;
}
for(int w=1;w<n;w<<=1)
{
m=p;
p=0;
for(int i=n;i>n-w;i--)id[++p]=i;
for(int i=1;i<=n;i++)if(sa[i]>w)id[++p]=sa[i]-w;
for(int i=1;i<=n;i++)key[i]=rk[id[i]];
for(int i=0;i<=m;i++)cnt[i]=0;
for(int i=1;i<=n;i++)cnt[key[i]]++;
for(int i=1;i<=m;i++)cnt[i]+=cnt[i-1];
for(int i=n;i>=1;i--)sa[cnt[key[i]]--]=id[i];
p=0;
for(int i=1;i<=n;i++)oldrk[i]=rk[i];
for(int i=1;i<=n;i++)
{
int x=sa[i],y=sa[i-1];
if(oldrk[x]!=oldrk[y]||oldrk[x+w]!=oldrk[y+w])p++;
rk[sa[i]]=p;
}
if(p==n)break;
}
for(int i=1;i<=n;i++)
{
cout<<sa[i]<<" ";
}
for(int i=1,k=0;i<=n;i++)
{
if(k)k--;
while(s[i+k]==s[sa[rk[i]-1]+k])k++;
height[rk[i]]=k;
}
cout<<endl;
for(int i=2;i<=n;i++)
{
cout<<height[i]<<" ";
}
cout<<endl;
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Subtask #1 Testcase #1 | 42.32 us | 84 KB | Accepted | Score: 100 | 显示更多 |
Subtask #1 Testcase #2 | 42.38 us | 88 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #3 | 41.89 us | 88 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #4 | 46.2 us | 92 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #5 | 45.45 us | 88 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #6 | 46.09 us | 92 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #7 | 20.326 ms | 3 MB + 696 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #8 | 36.296 ms | 3 MB + 916 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #9 | 22.219 ms | 3 MB + 784 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #10 | 14.389 ms | 2 MB + 552 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #11 | 15.171 ms | 2 MB + 592 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #12 | 28.59 ms | 3 MB + 980 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #13 | 27.137 ms | 3 MB + 1000 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #14 | 23.707 ms | 3 MB + 812 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #15 | 23.364 ms | 3 MB + 816 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #16 | 28.686 ms | 3 MB + 980 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #17 | 28.415 ms | 3 MB + 980 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #18 | 28.928 ms | 3 MB + 980 KB | Accepted | Score: 0 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2024-11-22 18:12:02 | Loaded in 2 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠