提交记录 17655


用户 题目 状态 得分 用时 内存 语言 代码长度
1443356159 1006. 【模板题】后缀排序 Accepted 100 59.818 ms 10248 KB C++ 987 B
提交时间 评测时间
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;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #136.04 us56 KBAcceptedScore: 0

Subtask #1 Testcase #21.563 ms7 MB + 696 KBAcceptedScore: 100

Subtask #1 Testcase #31.563 ms7 MB + 696 KBAcceptedScore: 0

Subtask #1 Testcase #43.587 ms7 MB + 696 KBAcceptedScore: 0

Subtask #1 Testcase #53.584 ms7 MB + 696 KBAcceptedScore: 0

Subtask #1 Testcase #64.26 ms7 MB + 696 KBAcceptedScore: 0

Subtask #1 Testcase #759.47 ms9 MB + 684 KBAcceptedScore: 0

Subtask #1 Testcase #859.818 ms9 MB + 872 KBAcceptedScore: 0

Subtask #1 Testcase #959.206 ms9 MB + 736 KBAcceptedScore: 0

Subtask #1 Testcase #1040.865 ms9 MB + 4 KBAcceptedScore: 0

Subtask #1 Testcase #1140.57 ms9 MB + 44 KBAcceptedScore: 0

Subtask #1 Testcase #1249.73 ms9 MB + 928 KBAcceptedScore: 0

Subtask #1 Testcase #1349.825 ms10 MB + 8 KBAcceptedScore: 0

Subtask #1 Testcase #1458.124 ms9 MB + 764 KBAcceptedScore: 0

Subtask #1 Testcase #1557.72 ms9 MB + 780 KBAcceptedScore: 0

Subtask #1 Testcase #1648.466 ms9 MB + 928 KBAcceptedScore: 0

Subtask #1 Testcase #1748.073 ms9 MB + 928 KBAcceptedScore: 0

Subtask #1 Testcase #1848.248 ms9 MB + 928 KBAcceptedScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2024-11-22 18:00:59 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠