提交记录 21488


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


CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #142.32 us84 KBAcceptedScore: 100

Subtask #1 Testcase #242.38 us88 KBAcceptedScore: 0

Subtask #1 Testcase #341.89 us88 KBAcceptedScore: 0

Subtask #1 Testcase #446.2 us92 KBAcceptedScore: 0

Subtask #1 Testcase #545.45 us88 KBAcceptedScore: 0

Subtask #1 Testcase #646.09 us92 KBAcceptedScore: 0

Subtask #1 Testcase #720.326 ms3 MB + 696 KBAcceptedScore: 0

Subtask #1 Testcase #836.296 ms3 MB + 916 KBAcceptedScore: 0

Subtask #1 Testcase #922.219 ms3 MB + 784 KBAcceptedScore: 0

Subtask #1 Testcase #1014.389 ms2 MB + 552 KBAcceptedScore: 0

Subtask #1 Testcase #1115.171 ms2 MB + 592 KBAcceptedScore: 0

Subtask #1 Testcase #1228.59 ms3 MB + 980 KBAcceptedScore: 0

Subtask #1 Testcase #1327.137 ms3 MB + 1000 KBAcceptedScore: 0

Subtask #1 Testcase #1423.707 ms3 MB + 812 KBAcceptedScore: 0

Subtask #1 Testcase #1523.364 ms3 MB + 816 KBAcceptedScore: 0

Subtask #1 Testcase #1628.686 ms3 MB + 980 KBAcceptedScore: 0

Subtask #1 Testcase #1728.415 ms3 MB + 980 KBAcceptedScore: 0

Subtask #1 Testcase #1828.928 ms3 MB + 980 KBAcceptedScore: 0


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