You are given a string S which consists of 250000 lowercase latin letters at most. We define F(x) as the maximal number of times that some string with length x appears in S. For example for string 'ababa' F(3) will be 2 because there is a string 'aba' that occurs twice. Your task is to output F(i) for every i so that 1<=i<=|S|.

Input

String S consists of at most 250000 lowercase latin letters.

Output

Output |S| lines. On the i-th line output F(i).

Example

Input:
ababa Output:
3
2
2
1
1

为什么我的后缀自动机写的这么奇怪qwq。。

为什么泥萌都在写桶排??!!

这题不是dfs一下求出$right$集合来就完了么qwq、、

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int MAXN = << , INF = 1e9 + ;
inline int read() {
char c = getchar(); int x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
char s[MAXN];
int N;
int f[MAXN], siz[MAXN], fa[MAXN], len[MAXN], ch[MAXN][], root = , last = , tot = ;
void insert(int x) {
int now = ++tot, pre = last; last = now;
siz[now] = ;
len[now] = len[pre] + ;
for(; pre && !ch[pre][x]; pre = fa[pre]) ch[pre][x] = now;
if(!pre) fa[now] = root;
else {
int q = ch[pre][x];
if(len[q] == len[pre] + ) fa[now] = q;
else {
int nows = ++tot;
memcpy(ch[nows], ch[q], sizeof(ch[q]));
fa[nows] = fa[q]; fa[q] = fa[now] = nows;
len[nows] = len[pre] + ;
for(; pre && ch[pre][x] == q; pre = fa[pre]) ch[pre][x] = nows;
}
}
}
vector<int> v[MAXN];
void dfs(int x) {
for(int i = ; i < v[x].size(); i++) {
dfs(v[x][i]);
siz[x] += siz[v[x][i]];
}
f[len[x]] = max(f[len[x]], siz[x]);
}
int main() {
#ifdef WIN32
freopen("a.in", "r", stdin);
#else
//freopen("pow.in", "r", stdin);
//freopen("pow.out", "w", stdout);
#endif
scanf("%s", s + );
N = strlen(s + );
for(int i = ; i <= N; i++) insert(s[i] - 'a');
for(int i = ; i <= tot; i++) v[fa[i]].push_back(i);
dfs(root);
for(int i = ; i <= N; i++)
printf("%d\n", f[i]);
return ;
}

SPOJ8222 NSUBSTR - Substrings(后缀自动机)的更多相关文章

  1. SPOJ8222 NSUBSTR - Substrings 后缀自动机_动态规划

    讲起来不是特别好讲.总之,如果 $dp[i+1]>=dp[i]$,故$dp[i]=max(dp[i],dp[i+1])$ Code: #include <cstdio> #inclu ...

  2. ●SPOJ 8222 NSUBSTR–Substrings(后缀自动机)

    题链: http://www.spoj.com/problems/NSUBSTR/ 题解: 后缀自动机的水好深啊!懂不了相关证明,带着结论把这个题做了.看来这滩深水要以后再来了. 本题要用到一个叫 R ...

  3. SPOJ NSUBSTR Substrings 后缀自动机

    人生第一道后缀自动机,总是值得纪念的嘛.. 后缀自动机学了很久很久,先是看CJL的论文,看懂了很多概念,关于right集,关于pre,关于自动机的术语,关于为什么它是线性的结点,线性的连边.许多铺垫的 ...

  4. SPOJ NSUBSTR Substrings ——后缀自动机

    建后缀自动机 然后统计次数,只需要算出right集合的大小即可, 然后更新f[l[i]]和rit[i]取个max 然后根据rit集合短的一定包含长的的性质,从后往前更新一遍即可 #include &l ...

  5. SP8222 NSUBSTR - Substrings(后缀自动机+dp)

    传送门 解题思路 首先建出\(sam\),然后把\(siz\)集合通过拓扑排序算出来.对于每个点只更新它的\(maxlen\),然后再从大到小\(dp\)一次就行了.因为\(f[maxlen-1]&g ...

  6. Substrings SPOJ - NSUBSTR (后缀自动机)

    Substrings \[ Time Limit: 100ms\quad Memory Limit: 1572864 kB \] 题意 给出一个长度为 \(250000\) 的字符串,求出所有 \(x ...

  7. 【CF316G3】Good Substrings 后缀自动机

    [CF316G3]Good Substrings 题意:给出n个限制(p,l,r),我们称一个字符串满足一个限制当且仅当这个字符串在p中的出现次数在[l,r]之间.现在想问你S的所有本质不同的子串中, ...

  8. SPOJ8222 NSUBSTR - Substrings

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...

  9. SPOJ8222 Substrings( 后缀自动机 + dp )

    题目大意:给一个字符串S,令F(x)表示S的所有长度为x的子串中,出现次数的最大值.F(1)..F(Length(S)) 建出SAM, 然后求出Right, 求Right可以按拓扑序dp..Right ...

随机推荐

  1. MySQL8.0加载文件内容报错: ERROR 1148: The used command is not allowed with this MySQL version

    mysql数据库将文件内容加载到表中报错: mysql> LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet LINES TERMINAT ...

  2. poj 1655 树的重心 && define注意事项

    http://blog.csdn.net/acdreamers/article/details/16905653 题意:给定一棵树,求树的重心的编号以及重心删除后得到的最大子树的节点个数size,如果 ...

  3. css3总结之居中

    居中在前端布局上很常见,也很常用,也是最基本的技巧.居中效果在方向控制上基本可以分解成水平居中,垂直居中和水平垂直居中. 针对调整的元素不同,具体的处理方式上有些差异.这里我们先不讲绝对定位下的居中, ...

  4. es6新增的数组方法和对象

    es6新增的遍历数组的方法,后面都会用这个方法来遍历数组,或者对象,还有set,map let arr=[1,2,3,4,3,2,1,2]; 遍历数组最简洁直接的方法法 for (let value ...

  5. Android应用开发基础之八:广播与服务(二)

    服务两种启动方式 startService:服务被启动之后,跟启动它的组件没有一毛钱关系 bindService:跟启动它的组件同生共死 绑定服务和解绑服务的生命周期方法:onCreate->o ...

  6. tcp/ip 调优示例

    # Kernel sysctl configuration file for Linux # # Version 1.12 - 2015-09-30 # Michiel Klaver - IT Pro ...

  7. Flask入门模板Jinja2语法与函数(四)

    1 模板的创建 模板文件结构: project/ templates/ 模板文件 跳转模板一般使用: from flask import render_template,render_template ...

  8. 【Spring实战】—— 9 AOP环绕通知

    假如有这么一个场景,需要统计某个方法执行的时间,如何做呢? 典型的会想到在方法执行前记录时间,方法执行后再次记录,得出运行的时间. 如果采用Spring的AOP,仅仅使用前置和后置方法是无法做到的,因 ...

  9. 扫描FTP,保存文件

    1.需求:某公司ftp服务器中一个文件夹中有30个文件(文件名字是不同的),每五分钟产生一个新的文件,同时删除这三十个文件中最早产生的文件,该文件夹中始终保持30个文件. 现在需要采集一周的数据做研究 ...

  10. March 21 2017 Week 12 Tuesday

    Sometimes ever, sometimes never. 相聚有时,后会无期. Maybe love is something we can't touch but we can feel w ...