提交记录 5450


用户 题目 状态 得分 用时 内存 语言 代码长度
Moon 1006. 【模板题】后缀排序 Wrong Answer 0 3.305 ms 1696 KB C++ 1.13 KB
提交时间 评测时间
2018-08-22 22:49:28 2020-08-01 00:17:31
//include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <cstring> 
#define rep(i,x,y) for (int i=x;i<=y;++i)
using namespace std;
const int N  =  2e5+233;
//const int mod = ;
struct Suffix_Array
{
	static const int M=260;
	int rk[N],tp[N],cnt[M],h[N],sa[N],n,m,p,i,j,k;
	int * x=rk,*y=tp;
	char str[N];
	inline void Init()
	{
		scanf("%s",str+1);
		n=strlen(str+1);
	}
	inline void Sort()
	{
		memset(cnt,0,sizeof(cnt));
		rep(i,1,n) ++cnt[x[tp[i]]];
		rep(i,1,m) cnt[i]+=cnt[i-1];
		for (int i=n;i>=1;--i) sa[cnt[x[y[i]]]--]=y[i];
	}
	inline int cmp(int *f,int x,int y,int w){return f[x]==f[y]&&f[x+w]==f[y+w];}
	inline void SA()
	{
		rep(i,1,n) x[i]=str[i],y[i]=i;
		m=256;Sort();
		for (int w=1;w<=n;w<<=1,m=p)
		{
			for (p=0,i=n-w+1;i<=n;++i) y[++p]=i;
			rep(i,1,n) if (sa[i]>w) y[++p]=sa[i]-w;
			Sort(),swap(x,y),x[sa[1]]=p=1;
			for (i=2;i<=n;++i) x[sa[i]]=cmp(tp,sa[i],sa[i-1],w) ?p :++p;
		}
		for (k=0,i=1;i<=n;h[rk[i++]]=k)
		  for (k? --k :0 ,j=sa[x[i]-1];str[j+k]==str[i+k];++k);
	}
}S;
signed main()
{
	S.Init();
	S.SA()	;
	rep(i,1,S.n) printf("%d ",S.sa[i]);puts("");
	rep(i,2,S.n) printf("%d ",S.h[i]) ;
	return 0;	
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #111.11 us36 KBWrong AnswerScore: 0

Subtask #1 Testcase #212.25 us36 KBAcceptedScore: 100

Subtask #1 Testcase #311.24 us36 KBAcceptedScore: 0

Subtask #1 Testcase #415.35 us36 KBWrong AnswerScore: -100

Subtask #1 Testcase #515.3 us36 KBWrong AnswerScore: 0

Subtask #1 Testcase #616.46 us36 KBWrong AnswerScore: 0

Subtask #1 Testcase #73.305 ms1 MB + 672 KBRuntime ErrorScore: 0

Subtask #1 Testcase #82.21 ms1 MB + 664 KBRuntime ErrorScore: 0

Subtask #1 Testcase #92.475 ms1 MB + 664 KBRuntime ErrorScore: 0

Subtask #1 Testcase #101.62 ms1 MB + 96 KBRuntime ErrorScore: 0

Subtask #1 Testcase #111.47 ms1 MB + 96 KBRuntime ErrorScore: 0

Subtask #1 Testcase #122.337 ms1 MB + 664 KBRuntime ErrorScore: 0

Subtask #1 Testcase #132.338 ms1 MB + 664 KBRuntime ErrorScore: 0

Subtask #1 Testcase #142.496 ms1 MB + 664 KBRuntime ErrorScore: 0

Subtask #1 Testcase #152.35 ms1 MB + 664 KBRuntime ErrorScore: 0

Subtask #1 Testcase #162.219 ms1 MB + 664 KBRuntime ErrorScore: 0

Subtask #1 Testcase #172.209 ms1 MB + 664 KBRuntime ErrorScore: 0

Subtask #1 Testcase #182.22 ms1 MB + 664 KBRuntime ErrorScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2026-04-11 21:03:16 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠