博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spoj NSUBSTR - Substrings
阅读量:4544 次
发布时间:2019-06-08

本文共 1684 字,大约阅读时间需要 5 分钟。

题目描述

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|.

输入输出格式

输入格式:

 

String S consists of at most 250000 lowercase latin letters.

 

输出格式:

 

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

 

输入输出样例

输入样例#1: 
ababa
输出样例#1: 
32211 对于每个节点x,i<=max{x}的f(i)都可以被size[x]更新,所以差分打个标记就可以了hhhh 今天刷后缀自动机真过瘾hhhh
#include
#include
#include
#include
#include
#define maxn 1000005using namespace std;int f[maxn],ch[maxn][26];int l[maxn],siz[maxn],n;int tag[maxn],cnt=1,pre=1;int a[maxn],c[maxn];char s[maxn];inline void ins(int x){ int p=pre,np=++cnt; pre=np,l[np]=l[p]+1; siz[np]=1; for(;p&&!ch[p][x];p=f[p]) ch[p][x]=np; if(!p) f[np]=1; else{ int q=ch[p][x]; if(l[q]==l[p]+1) f[np]=q; else{ int nq=++cnt; l[nq]=l[p]+1; memcpy(ch[nq],ch[q],sizeof(ch[q])); f[nq]=f[q]; f[q]=f[np]=nq; for(;ch[p][x]==q;p=f[p]) ch[p][x]=nq; } }}inline void build(){ for(int i=0;i
=0;i--) c[i]+=c[i+1]; for(int i=1;i<=cnt;i++) a[c[l[i]]--]=i;}inline void solve(){ for(int i=1;i<=cnt;i++){ int now=a[i]; siz[f[now]]+=siz[now]; tag[l[now]]=max(tag[l[now]],siz[now]); } for(int i=n;i;i--) tag[i]=max(tag[i],tag[i+1]);}int main(){ scanf("%s",s); n=strlen(s); build(); solve(); for(int i=1;i<=n;i++) printf("%d\n",tag[i]); return 0;}
 

  

 

转载于:https://www.cnblogs.com/JYYHH/p/8457348.html

你可能感兴趣的文章
codeforces 993 A
查看>>
gridview表头不生成<th>
查看>>
Jetty:部署到Jetty
查看>>
在XP上安装VS2002
查看>>
linux程序设计——网络信息(第十五章)
查看>>
待补的坑
查看>>
算法稳定性
查看>>
static关键字详解
查看>>
python删除列表中元素的方法
查看>>
进程与线程(2)- python实现多进程
查看>>
MySQL性能优化的最佳20+条经验
查看>>
GUI线程安全详解(二)
查看>>
编写一个Servlet,将表单提交的商品信息输出到页面中
查看>>
使用.NET Core与Google Optimization Tools实现加工车间任务规划
查看>>
成都Uber优步司机奖励政策(3月22日)
查看>>
How to capture video frames from the camera as images using AV Foundation
查看>>
静态变量、实例变量、局部变量与线程安全
查看>>
Oracle 11.2.0.4.0 Dataguard部署和日常维护(6)-Dataguard Snapshot篇
查看>>
python基础语法_9-2函数式编程
查看>>
js实现文字超出部分用省略号代替实例代码
查看>>