提交记录 16150


用户 题目 状态 得分 用时 内存 语言 代码长度
ynycoding 1006. 【模板题】后缀排序 Wrong Answer 0 22.013 ms 4868 KB C++11 2.13 KB
提交时间 评测时间
2021-04-15 11:26:19 2021-04-15 11:26:23
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 100005
namespace iobuff{
	const int LEN=1000000;
	char in[LEN+5], out[LEN+5];
	char *pin=in, *pout=out, *ed=in, *eout=out+LEN;
	inline char gc(void)
	{
		return pin==ed&&(ed=(pin=in)+fread(in, 1, LEN, stdin), ed==in)?EOF:*pin++;
	}
	inline void pc(char c)
	{
		pout==eout&&(fwrite(out, 1, LEN, stdout), pout=out);
		(*pout++)=c;
	}
	inline void flush()
	{ fwrite(out, 1, pout-out, stdout), pout=out; }
	template<typename T> inline void scan(T &x)
	{
		static int f;
		static char c;
		c=gc(), f=1, x=0;
		while(c<'0'||c>'9') f=(c=='-'?-1:1), c=gc();
		while(c>='0'&&c<='9') x=10*x+c-'0', c=gc();
		x*=f;
	}
	template<typename T> inline void putint(T x, char div)
	{
		static char s[15];
		static int top;
		top=0;
		x<0?pc('-'), x=-x:0;
		while(x) s[top++]=x%10, x/=10;
		!top?pc('0'), 0:0;
		while(top--) pc(s[top]+'0');
		pc(div);
	}
}
using namespace iobuff;
int n, *rk, *ork, rid[N], pool[2][N], sa[N], cnt[N], id[N], h[N], tp;
char s[N];
inline int eq(int x, int y, int len) { return ork[x]==ork[y]&&ork[x+len]==ork[y+len]; }
inline void SA(void)
{
	rk=pool[0], ork=pool[1];
	for(int i=1; i<=n; ++i) ++cnt[rk[i]=s[i]-'a'+1];
	for(int i=1; i<=26; ++i) cnt[i]+=cnt[i-1];
	for(int i=1; i<=n; ++i) sa[cnt[rk[i]]--]=i;
	for(int len=1, lim=0; lim!=n; len<<=1)
	{
		if(!lim) lim=26;
		tp=0;
		for(int i=n-len+1; i<=n; ++i) id[++tp]=i;
		for(int i=1; i<=n; ++i) if(sa[i]>len) id[++tp]=sa[i]-len;
		
		std::fill(cnt+1, cnt+lim+1, 0);
		for(int i=1; i<=n; ++i) ++cnt[rk[i]];
		for(int i=1; i<=lim; ++i) cnt[i]+=cnt[i-1];
		for(int i=1; i<=n; ++i) rid[i]=rk[id[i]];
		for(int i=n; i; --i) sa[cnt[rid[i]]--]=id[i];
		
		std::swap(rk, ork);
		lim=0;
		for(int i=1; i<=n; ++i)
		{
			if(i==1||(!eq(sa[i-1], sa[i], len))) rk[sa[i]]=++lim;
			else rk[sa[i]]=lim;
		}
	}
}
inline void gheight(void)
{
	for(int i=1, k=0; i<=n; ++i)
	{
		if(rk[i]==1) continue;
		if(k) --k;
		int j=sa[rk[i]-1];
		while(s[i+k]==s[j+k]) ++k;
		h[rk[i]]=k;
	}
}
int main()
{
	scanf("%s", s+1);
	n=strlen(s+1);
	SA();
	gheight();
	for(int i=1; i<=n; ++i) putint(sa[i], ' ');
	pc('\n');
	for(int i=2; i<=n; ++i) putint(h[i], ' ');
	flush();
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #110.1 us56 KBWrong AnswerScore: -100

Subtask #1 Testcase #213.06 us56 KBAcceptedScore: 100

Subtask #1 Testcase #313 us56 KBAcceptedScore: 0

Subtask #1 Testcase #412.79 us56 KBAcceptedScore: 0

Subtask #1 Testcase #511.85 us56 KBAcceptedScore: 0

Subtask #1 Testcase #611.61 us56 KBAcceptedScore: 0

Subtask #1 Testcase #75.746 ms4 MB + 256 KBAcceptedScore: 0

Subtask #1 Testcase #822.013 ms4 MB + 664 KBAcceptedScore: 0

Subtask #1 Testcase #97.908 ms4 MB + 396 KBAcceptedScore: 0

Subtask #1 Testcase #104.977 ms2 MB + 908 KBAcceptedScore: 0

Subtask #1 Testcase #115.667 ms2 MB + 988 KBAcceptedScore: 0

Subtask #1 Testcase #1213.561 ms4 MB + 748 KBAcceptedScore: 0

Subtask #1 Testcase #1312.139 ms4 MB + 772 KBAcceptedScore: 0

Subtask #1 Testcase #149.2 ms4 MB + 452 KBAcceptedScore: 0

Subtask #1 Testcase #158.905 ms4 MB + 476 KBAcceptedScore: 0

Subtask #1 Testcase #1612.493 ms4 MB + 748 KBAcceptedScore: 0

Subtask #1 Testcase #1712.301 ms4 MB + 748 KBAcceptedScore: 0

Subtask #1 Testcase #1812.626 ms4 MB + 748 KBAcceptedScore: 0


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