提交记录 5448


用户 题目 状态 得分 用时 内存 语言 代码长度
Moon 1006. 【模板题】后缀排序 Wrong Answer 0 55.56 ms 3984 KB C++ 1.34 KB
提交时间 评测时间
2018-08-22 22:40:36 2020-08-01 00:17:25
//include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring> 
#include <set>
#include <map>
#define db double 
#define LL long long
//#define int LL
#define rep(i,x,y) for (int i=x;i<=y;++i)
#define mp make_pair
#define ft first
#define sd second
#define P pair<int ,int >
#define pb push_back 
using namespace std;
const int N  =  2e5+233;
//const int mod = ;
struct Suffix_Array
{
	static const int M=N;
	int rk[N],tp[N],cnt[M],h[N],sa[N],n,m,p,i,j,k;
	char str[N];
	void Init()
	{
		scanf("%s",str+1);
		n=strlen(str+1);
	}
	void Sort()
	{
		//memset(cnt,0,sizeof(cnt));
		rep(i,0,m) cnt[i]=0;
		rep(i,1,n) ++cnt[rk[tp[i]]];
		rep(i,1,m) cnt[i]+=cnt[i-1];
		for (int i=n;i>=1;--i) sa[cnt[rk[tp[i]]]--]=tp[i];
	}
	int cmp(int *f,int x,int y,int w){return f[x]==f[y]&&f[x+w]==f[y+w];}
	void SA()
	{
		rep(i,1,n) rk[i]=str[i],tp[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) tp[++p]=i;
			rep(i,1,n) if (sa[i]>w) tp[++p]=sa[i]-w;
			Sort(),swap(rk,tp),rk[sa[1]]=p=1;
			for (i=2;i<=n;++i) rk[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[rk[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 #1316.11 us1 MB + 572 KBWrong AnswerScore: -100

Subtask #1 Testcase #2444.41 us1 MB + 572 KBAcceptedScore: 0

Subtask #1 Testcase #3445.2 us1 MB + 572 KBAcceptedScore: 100

Subtask #1 Testcase #4824.01 us1 MB + 572 KBAcceptedScore: 0

Subtask #1 Testcase #5698.27 us1 MB + 572 KBAcceptedScore: 0

Subtask #1 Testcase #6824.73 us1 MB + 572 KBAcceptedScore: 0

Subtask #1 Testcase #755.56 ms3 MB + 564 KBAcceptedScore: 0

Subtask #1 Testcase #852.121 ms3 MB + 752 KBAcceptedScore: 0

Subtask #1 Testcase #955.105 ms3 MB + 616 KBAcceptedScore: 0

Subtask #1 Testcase #1035.504 ms2 MB + 904 KBAcceptedScore: 0

Subtask #1 Testcase #1134.884 ms2 MB + 944 KBAcceptedScore: 0

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

Subtask #1 Testcase #1339.776 ms3 MB + 912 KBAcceptedScore: 0

Subtask #1 Testcase #1453.346 ms3 MB + 644 KBAcceptedScore: 0

Subtask #1 Testcase #1552.591 ms3 MB + 660 KBAcceptedScore: 0

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

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

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


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