#include<iostream>
#include<cstdio>
#include<cstring>
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;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Subtask #1 Testcase #1 | 36.17 us | 52 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #2 | 45.36 us | 52 KB | Accepted | Score: 100 | 显示更多 |
| Subtask #1 Testcase #3 | 43.54 us | 52 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #4 | 43.26 us | 56 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #5 | 44.54 us | 56 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #6 | 43.7 us | 56 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #7 | 59.609 ms | 31 MB + 132 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #8 | 60.335 ms | 40 MB + 120 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #9 | 67.245 ms | 41 MB + 676 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #10 | 41.974 ms | 27 MB + 528 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #11 | 43.873 ms | 31 MB + 924 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #12 | 36.989 ms | 29 MB + 112 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #13 | 54.453 ms | 44 MB + 848 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #14 | 53.086 ms | 34 MB + 620 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #15 | 64.753 ms | 48 MB + 212 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #16 | 41.124 ms | 26 MB + 840 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #17 | 48.777 ms | 25 MB + 456 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #18 | 48.058 ms | 25 MB + 188 KB | Accepted | Score: 0 | 显示更多 |