提交记录 16160


用户 题目 状态 得分 用时 内存 语言 代码长度
ynycoding 1006. 【模板题】后缀排序 Accepted 100 8.162 ms 4472 KB C++11 3.02 KB
提交时间 评测时间
2021-04-15 11:35:27 2021-04-15 11:35:32
#pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline", "-ftree-vectorize", "-fopt-info-vec-all")
#pragma GCC option("arch=native", "tune=native", "no-zero-upper")
#pragma GCC target("sse,sse2,sse3,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2")

#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 200005
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, s[N], s1[N], sa[N], cnt[N], p[N], rk[N], idx[N];//type S:0 L:1
bool t[N];
#define pushl(x) sa[idx[s[x]]++]=x
#define pushs(x) sa[idx[s[x]]--]=x
inline void inducedsort(int *s, bool *t, int *sa, int *cnt, int n, int m, int *v, int top)
{
	std::fill(sa+1, sa+n+1, 0);
	memcpy(idx, cnt, sizeof(int)*(m+1));
	for(int i=top; i; --i) pushs(v[i]);
	for(int i=1; i<=m; ++i) idx[i]=cnt[i-1]+1;
	for(int i=1; i<=n; ++i)
	{
		int x=sa[i]-1;
		if(x&&t[x]) pushl(x);
	}
	memcpy(idx, cnt, sizeof(int)*(m+1));
	for(int i=n; i; --i)
	{
		int x=sa[i]-1;
		if(x&&!t[x]) pushs(x);
	}
}
void SAIS(int *s, bool *t, int *p, int *cnt, int n, int m)
{
	int top=0, *s1=s+n+1;
	t[n]=0;
	for(int i=1; i<=n; ++i) ++cnt[s[i]];
	for(int i=1; i<=m; ++i) cnt[i]+=cnt[i-1];
	for(int i=n-1; i; --i) t[i]=(s[i]>s[i+1]||(s[i]==s[i+1]&&t[i+1]));
	for(int i=2; i<=n; ++i) rk[i]=((t[i-1]&&!t[i])?(p[++top]=i, top):0);
	inducedsort(s, t, sa, cnt, n, m, p, top);
	int nm=0;
	for(int i=1, x=0, y=0; i<=n; ++i) if(x=rk[sa[i]])
	{
		if(!m||p[x+1]-p[x]!=p[y+1]-p[y]) ++nm;
		else
		{
			for(int l=p[x], r=p[y]; l<=p[x+1]; ++l, ++r)
				if(s[l]!=s[r]) { ++nm; break; }
		}
		y=x;
		s1[x]=nm;
	}
	if(nm<top) SAIS(s1, t+n+1, p+n+1, cnt+m+1, top, nm);
	else for(int i=1; i<=top; ++i) sa[s1[i]]=i;
	for(int i=1; i<=top; ++i) s1[i]=p[sa[i]];
	inducedsort(s, t, sa, cnt, n, m, s1, top);
}
char rs[N];
int h[N];
inline void gheight(void)
{
	for(int i=1; i<=n; ++i) rk[sa[i]]=i;
	for(int i=1, k=0; i<=n; ++i) if(rk[i]<n)
	{
		int j=sa[rk[i]+1];
		k=std::max(0, k-1);
		while(rs[i+k]==rs[j+k]) ++k;
		h[rk[i]]=k;
	}
}
int main()
{
	scanf("%s", rs+1);
	n=strlen(rs+1);
	for(int i=1; i<=n; ++i) s[i]=rs[i]-'a'+2;
	s[++n]=1;
	SAIS(s, t, p, cnt, n, 27);
	for(int i=1; i<n; ++i) sa[i]=sa[i+1];
	sa[n]=0;
	--n;
	for(int i=1; i<=n; ++i) putint(sa[i], ' ');
	pc('\n');
	gheight();
	for(int i=1; i<n; ++i) putint(h[i], ' ');
	pc('\n');
	flush();
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #113.02 us56 KBAcceptedScore: 0

Subtask #1 Testcase #214.91 us56 KBAcceptedScore: 100

Subtask #1 Testcase #316.28 us56 KBAcceptedScore: 0

Subtask #1 Testcase #415.12 us56 KBAcceptedScore: 0

Subtask #1 Testcase #515.21 us56 KBAcceptedScore: 0

Subtask #1 Testcase #613.95 us56 KBAcceptedScore: 0

Subtask #1 Testcase #77.133 ms3 MB + 836 KBAcceptedScore: 0

Subtask #1 Testcase #88.162 ms4 MB + 16 KBAcceptedScore: 0

Subtask #1 Testcase #98.108 ms3 MB + 796 KBAcceptedScore: 0

Subtask #1 Testcase #105.2 ms2 MB + 492 KBAcceptedScore: 0

Subtask #1 Testcase #114.978 ms2 MB + 528 KBAcceptedScore: 0

Subtask #1 Testcase #124.751 ms3 MB + 860 KBAcceptedScore: 0

Subtask #1 Testcase #134.679 ms3 MB + 828 KBAcceptedScore: 0

Subtask #1 Testcase #144.861 ms3 MB + 552 KBAcceptedScore: 0

Subtask #1 Testcase #154.927 ms3 MB + 608 KBAcceptedScore: 0

Subtask #1 Testcase #165 ms4 MB + 284 KBAcceptedScore: 0

Subtask #1 Testcase #174.933 ms4 MB + 376 KBAcceptedScore: 0

Subtask #1 Testcase #184.851 ms4 MB + 348 KBAcceptedScore: 0


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