提交记录 21623


用户 题目 状态 得分 用时 内存 语言 代码长度
LiZYX 1006. 【模板题】后缀排序 Accepted 100 36.411 ms 3268 KB C++ 1.13 KB
提交时间 评测时间
2024-04-16 21:02:52 2024-04-16 21:02:57
#include<iostream>
#include<string.h>
using namespace std;
const int N=100005;
int n,sa[N],rk[N],h[N];
char a[N];
namespace SA{
	int cnt[N],la[N];
	void getsa(){
		memset(cnt,0,sizeof(cnt));
		for(int i=1;i<=n;++i)rk[i]=a[i],++cnt[a[i]];
		for(int i=1;i<128;++i)cnt[i]+=cnt[i-1];
		for(int i=n;i;--i)sa[cnt[a[i]]--]=i;
		for(int o=1,now,m=128;o<n;o<<=1){
			memset(cnt,0,sizeof(cnt));
			now=0;
			for(int i=1;i<=n;++i)++cnt[rk[i]];
			for(int i=n-o+1;i<=n;++i)la[++now]=i;
			for(int i=1;i<=n;++i)
			if(sa[i]>o)la[++now]=sa[i]-o;
			for(int i=1;i<=m;++i)cnt[i]+=cnt[i-1];
			for(int i=n;i;--i)sa[cnt[rk[la[i]]]--]=la[i];
			m=0;
			swap(la,rk);
			for(int i=1;i<=n;++i)
				if(la[sa[i]]==la[sa[i-1]]&&la[sa[i]+o]==la[sa[i-1]+o])rk[sa[i]]=m;
				else rk[sa[i]]=++m;
			if(m==n)break;
		}
	}
	void getht(){
		for(int i=1,o=0,la;i<=n;++i){
			o=max(0,o-1);
			la=sa[rk[i]-1];
			while(a[la+o]==a[i+o])++o;
			h[rk[i]]=o;
		}
	}
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	cin>>(a+1);
	n=strlen(a+1);
	SA::getsa();
	SA::getht();
	for(int i=1;i<=n;++i)
		cout<<sa[i]<<" ";
	cout<<'\n';
	for(int i=2;i<=n;++i)
		cout<<h[i]<<" ";
	cout<<'\n';
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #177.97 us472 KBAcceptedScore: 100

Subtask #1 Testcase #2233.57 us1 MB + 220 KBAcceptedScore: 0

Subtask #1 Testcase #3233.04 us1 MB + 220 KBAcceptedScore: 0

Subtask #1 Testcase #4376.64 us1 MB + 220 KBAcceptedScore: 0

Subtask #1 Testcase #5376.75 us1 MB + 220 KBAcceptedScore: 0

Subtask #1 Testcase #6377.07 us1 MB + 220 KBAcceptedScore: 0

Subtask #1 Testcase #720.165 ms2 MB + 840 KBAcceptedScore: 0

Subtask #1 Testcase #836.411 ms3 MB + 4 KBAcceptedScore: 0

Subtask #1 Testcase #922.247 ms2 MB + 892 KBAcceptedScore: 0

Subtask #1 Testcase #1014.557 ms2 MB + 304 KBAcceptedScore: 0

Subtask #1 Testcase #1115.394 ms2 MB + 344 KBAcceptedScore: 0

Subtask #1 Testcase #1228.082 ms3 MB + 196 KBAcceptedScore: 0

Subtask #1 Testcase #1326.737 ms3 MB + 164 KBAcceptedScore: 0

Subtask #1 Testcase #1423.666 ms2 MB + 920 KBAcceptedScore: 0

Subtask #1 Testcase #1523.37 ms2 MB + 936 KBAcceptedScore: 0

Subtask #1 Testcase #1626.852 ms3 MB + 196 KBAcceptedScore: 0

Subtask #1 Testcase #1726.541 ms3 MB + 196 KBAcceptedScore: 0

Subtask #1 Testcase #1826.76 ms3 MB + 196 KBAcceptedScore: 0


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