提交记录 17655
提交时间 |
评测时间 |
2022-04-13 10:57:10 |
2022-04-13 10:57:15 |
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
char S[N];
int n,m,num,id[N],sa[N],cnt[N],h[N],rk[N];
void suffix_sort() {
m=300;
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 k=1;k<n;k<<=1) {
num=0;
for(int i=n-k+1;i<=n;++i)id[++num]=i;
for(int i=1;i<=n;++i)if(sa[i]>k)id[++num]=sa[i]-k;
for(int i=1;i<=m;++i)cnt[i]=0;
for(int i=1;i<=n;++i)++cnt[rk[i]];
for(int i=1;i<=m;++i)cnt[i]+=cnt[i-1];
for(int i=n;i>=1;--i)sa[cnt[rk[id[i]]]--]=id[i],id[i]=0;
swap(rk,id);rk[sa[1]]=num=1;
for(int i=2;i<=n;++i)
rk[sa[i]]=(id[sa[i]]==id[sa[i-1]]&&id[sa[i]+k]==id[sa[i-1]+k])?num:++num;
m=num;
}
for(int i=1,j=0;i<=n;++i) {
if(j)--j;
while(S[i+j]==S[sa[rk[i]-1]+j])++j;
h[rk[i]]=j;
}
}
int main() {
scanf("%s",S+1);n=strlen(S+1);
suffix_sort();
for(int i=1;i<=n;++i)printf("%d ",sa[i]);puts("");
for(int i=2;i<=n;++i)printf("%d ",h[i]);puts("");
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Subtask #1 Testcase #1 | 36.04 us | 56 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #2 | 1.563 ms | 7 MB + 696 KB | Accepted | Score: 100 | 显示更多 |
Subtask #1 Testcase #3 | 1.563 ms | 7 MB + 696 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #4 | 3.587 ms | 7 MB + 696 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #5 | 3.584 ms | 7 MB + 696 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #6 | 4.26 ms | 7 MB + 696 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #7 | 59.47 ms | 9 MB + 684 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #8 | 59.818 ms | 9 MB + 872 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #9 | 59.206 ms | 9 MB + 736 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #10 | 40.865 ms | 9 MB + 4 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #11 | 40.57 ms | 9 MB + 44 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #12 | 49.73 ms | 9 MB + 928 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #13 | 49.825 ms | 10 MB + 8 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #14 | 58.124 ms | 9 MB + 764 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #15 | 57.72 ms | 9 MB + 780 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #16 | 48.466 ms | 9 MB + 928 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #17 | 48.073 ms | 9 MB + 928 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #18 | 48.248 ms | 9 MB + 928 KB | Accepted | Score: 0 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2024-11-22 18:00:59 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠