提交记录 3393


用户 题目 状态 得分 用时 内存 语言 代码长度
oscar 1006. 【模板题】后缀排序 Accepted 100 66.619 ms 49336 KB C++ 1.94 KB
提交时间 评测时间
2018-07-14 18:48:52 2020-07-31 21:16:47
#include<stdio.h>
#include<string.h>
#include<vector>
using namespace std;
const int sigma=26,MAXN=233333;
struct node
{
	int maxlen,fastlen;
	bool isend;
	node *next[sigma],*link,*fast;
}*root,pool[MAXN],*last;
int top,totlen;
char buf[MAXN],str[MAXN];
void add(int ch)
{
	node *p=last,*cur=&pool[++top];
	cur->maxlen=p->maxlen+1;
	while(p&&!p->next[ch])
	{
		p->next[ch]=cur;
		p=p->link;
	}
	if(!p)
		cur->link=root;
	else
	{
		node *q=p->next[ch];
		if(p->maxlen+1==q->maxlen)cur->link=q;
		else
		{
			node *sq=&pool[++top];
			sq->maxlen=p->maxlen+1;
			for(int i=0;i<sigma;i++)
				sq->next[i]=q->next[i];
			while(p&&p->next[ch]==q)
			{
				p->next[ch]=sq;
				p=p->link;
			}
			sq->link=q->link;
			q->link=sq;
			cur->link=sq;
		}
	}
	last=cur;
}
inline void update()
{
	node *p=last;
	while(p!=root)
	{
		p->isend=1;
		p=p->link;
	}
	for(int i=1;i<=top;i++)
	{
		node *t=&pool[i],*q=0;
		if(t->isend)continue;
		int c=0;
		for(int ch=0;ch<sigma;ch++)
		{
			if(t->next[ch])
				++c,q=t->next[ch];
		}
		if(c==1)
		{
			t->fast=q;
			t->fastlen=1;
		}
	}
}
int lcp[MAXN],minn,cnt;
typedef pair<node*,int> pni;
#define mp make_pair
pni find(node *u)
{
	if(!u->fast)return mp(u,0);
	pni _=find(u->fast);
	u->fast=_.first;
	u->fastlen+=_.second;
	return mp(u->fast,u->fastlen);
}
void dfs(node *u,int len=0)
{
	//cout<<"dfs "<<len<<endl;
	if(u->isend)
	{
		printf("%d ",totlen-len+1);
		//printf("%s\n",str);
		lcp[++cnt]=minn;
		minn=len;
	}
	if(u->fast)
	{
		find(u);
		dfs(u->fast,len+u->fastlen);
	}
	else
		for(int x=0;x<sigma;x++)
		{
			if(u->next[x])
			{
				//str[len]=x+'a';
				if(len<minn)minn=len;
				dfs(u->next[x],len+1);
			}
		}
	//str[len]=0;
}
int main()
{
	//freopen("data.in","r",stdin);
	//freopen("dump.txt","w",stdout);
	scanf("%s",buf);
	totlen=strlen(buf);
	last=root=&pool[++top];
	for(int i=0;i<totlen;++i)
	{
		add(buf[i]-'a');
	}
	update();
	dfs(root);
	printf("\n");
	for(int i=2;i<=totlen;i++)
		printf("%d ",lcp[i]);
	printf("\n");
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #19.46 us28 KBAcceptedScore: 0

Subtask #1 Testcase #214.03 us28 KBAcceptedScore: 100

Subtask #1 Testcase #314.62 us28 KBAcceptedScore: 0

Subtask #1 Testcase #416.5 us32 KBAcceptedScore: 0

Subtask #1 Testcase #516.06 us32 KBAcceptedScore: 0

Subtask #1 Testcase #615.09 us32 KBAcceptedScore: 0

Subtask #1 Testcase #759.067 ms31 MB + 104 KBAcceptedScore: 0

Subtask #1 Testcase #859.388 ms40 MB + 96 KBAcceptedScore: 0

Subtask #1 Testcase #966.619 ms41 MB + 652 KBAcceptedScore: 0

Subtask #1 Testcase #1041.529 ms27 MB + 504 KBAcceptedScore: 0

Subtask #1 Testcase #1143.215 ms31 MB + 900 KBAcceptedScore: 0

Subtask #1 Testcase #1237.074 ms29 MB + 88 KBAcceptedScore: 0

Subtask #1 Testcase #1353.689 ms44 MB + 824 KBAcceptedScore: 0

Subtask #1 Testcase #1453.393 ms34 MB + 596 KBAcceptedScore: 0

Subtask #1 Testcase #1564.729 ms48 MB + 184 KBAcceptedScore: 0

Subtask #1 Testcase #1640.55 ms26 MB + 816 KBAcceptedScore: 0

Subtask #1 Testcase #1747.571 ms25 MB + 432 KBAcceptedScore: 0

Subtask #1 Testcase #1848.03 ms25 MB + 164 KBAcceptedScore: 0


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