fastle
垆边人似月 皓腕凝霜雪
/*
求right集合大小 
然后后缀最大值 

*/
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
#define ll long long 
#define M 600010
#define mmp make_pair
using namespace std;
int read()
{
	int nm = 0, f = 1;
	char c = getchar();
	for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
	for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
	return nm * f;
}
char s[M];
int ch[M][26], sz[M], ans[M], tim[M], a[M], fa[M], len[M], cnt = 1, lst = 1; 

void insert(int c)
{
	int p = ++cnt, f = lst;
	lst = cnt;
	len[p] = len[f] + 1;
	sz[p] = 1;
	while(f && !ch[f][c]) ch[f][c] = p, f = fa[f];
	if(!f) fa[p] = 1;
	else
	{
		int q = ch[f][c];
		if(len[q] == len[f] + 1) fa[p] = q;
		else
		{
			int nq = ++cnt;
			fa[nq] = fa[q];
			len[nq] = len[f] + 1;
			memcpy(ch[nq], ch[q], sizeof(ch[nq]));
			fa[p] = fa[q] = nq;
			while(f && ch[f][c] == q) ch[f][c] = nq, f = fa[f];
		}
	}
}
	

int main()
{
	scanf("%s", s + 1);
	int l = strlen(s + 1);
	for(int i = 1; i <= l; i++) insert(s[i] - 'a');
	for(int i = 1; i <= cnt; i++) tim[len[i]]++;
	for(int i = 1; i <= cnt; i++) tim[i] += tim[i - 1];
	for(int i = 1; i <= cnt; i++) a[tim[len[i]]--] = i;
	for(int i = cnt; i >= 1; i--)
	{
		sz[fa[a[i]]] += sz[a[i]];
		ans[len[a[i]]] = max(ans[len[a[i]]], sz[a[i]]);
	}
	for(int i = cnt; i >= 1; i--) ans[i] = max(ans[i], ans[i + 1]);
	for(int i = 1; i <= l; i++) cout << ans[i] << "\n"; 
	return 0;
}
posted on 2019-03-28 08:35  fastle  阅读(115)  评论(0编辑  收藏  举报