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

  1. Input:
    ababa
  2.  
  3. Output:
    3
    2
    2
    1
    1
  4.  
  5. 题解:
    这..比上题还简单啊,根据parent树上父节点为子节点的最大子集,直接统计size即可,
    英语不好看成了求和........3WA
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include <cstring>
  5. #include <cstdio>
  6. #include <cmath>
  7. using namespace std;
  8. const int N=,M=;
  9. char s[N];int n,last=,cnt=,cur=,dis[M],ch[M][],fa[M],size[M];
  10. void build(int j){
  11. int c=s[j]-'a';
  12. last=cur;cur=++cnt;
  13. int p=last;dis[cur]=j;
  14. for(;p && !ch[p][c];p=fa[p])ch[p][c]=cur;
  15. if(!p)fa[cur]=;
  16. else{
  17. int q=ch[p][c];
  18. if(dis[q]==dis[p]+)fa[cur]=q;
  19. else{
  20. int nt=++cnt;
  21. dis[nt]=dis[p]+;
  22. memcpy(ch[nt],ch[q],sizeof(ch[q]));
  23. fa[nt]=fa[q];fa[q]=fa[cur]=nt;
  24. for(;ch[p][c]==q;p=fa[p])ch[p][c]=nt;
  25. }
  26. }
  27. size[cur]=;
  28. }
  29. int sa[M];long long ans[N],c[N];
  30. void Flr(){
  31. int p;
  32. for(int i=;i<=cnt;i++)c[dis[i]]++;
  33. for(int i=;i<=n;i++)c[i]+=c[i-];
  34. for(int i=cnt;i>=;i--)sa[c[dis[i]]--]=i;
  35. for(int i=cnt;i>=;i--){
  36. p=sa[i];
  37. if(size[p]>ans[dis[p]])ans[dis[p]]=size[p];
  38. size[fa[p]]+=size[p];
  39. }
  40. }
  41. void work(){
  42. scanf("%s",s+);
  43. n=strlen(s+);
  44. for(int i=;i<=n;i++)build(i);
  45. Flr();
  46. for(int i=;i<=n;i++)printf("%lld\n",ans[i]);
  47. }
  48. int main()
  49. {
  50. //freopen("pp.in","r",stdin);
  51. work();
  52. return ;
  53. }
  1.  
  1.  

SPOJ NSUBSTR的更多相关文章

  1. SPOJ - NSUBSTR 后缀自动机板子

    SPOJ - NSUBSTR #include<bits/stdc++.h> #define LL long long #define fi first #define se second ...

  2. SPOJ NSUBSTR (后缀自动机)

    SPOJ NSUBSTR Problem : 给一个长度为n的字符串,要求分别输出长度为1~n的子串的最多出现次数. Solution :首先对字符串建立后缀自动机,在根据fail指针建立出后缀树,对 ...

  3. 【spoj NSUBSTR】 Substrings

    http://www.spoj.com/problems/NSUBSTR/ (题目链接) 题意 给出一个字符串S,令${F(x)}$表示S的所有长度为x的子串出现次数的最大值.求${F(1)..... ...

  4. SPOJ NSUBSTR Substrings 后缀自动机

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

  5. SPOJ NSUBSTR Substrings

    题意 dt { font-weight: bold; margin-top: 20px; padding-left: 35px; } dd { box-shadow: 3px 3px 6px #888 ...

  6. SPOJ - NSUBSTR(长度为1-len的字串出现的最大次数

    题意:给你一个字符串,要你输出1-len的字串出现的最大次数. /** @xigua */ #include <stdio.h> #include <cmath> #inclu ...

  7. 【SPOJ -NSUBSTR】Substrings 【后缀自动机+dp】

    题意 给出一个字符串,要你找出所有长度的子串分别的最多出现次数. 分析 我们建出后缀自动机,然后预处理出每个状态的cnt,cnt[u]指的是u这个状态的right集合大小.我们设f[len]为长度为l ...

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

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

  9. spoj NSUBSTR - Substrings【SAM】

    先求个SAM,然后再每个后缀的对应点上标记si[nw]=1,造好SAM之后用吧parent树建出来把si传上去,然后用si[u]更新f[max(u)],最后用j>i的[j]更新f[i] 因为每个 ...

随机推荐

  1. Python 线程复习

    修改全局变量,设立flag来避免线程间数据冲突,低效率版 from threading import Thread import time g_num=0 g_flag = 1 def test1() ...

  2. iOS开发-OC中TabView的编辑

    UITableView编辑 1> UITableView 编辑流程 2> UITableView 编辑步骤(四步) ① 第一步 : 让 TableView 处于编辑状态(在按钮点击事件方法 ...

  3. 使用SecureCRTP 连接生产环境的web服务器和数据库服务器

    一.使用SecureCRTP 连接生产环境的web服务器 首先,需要知道以下参数信息: 1.web服务器的ip地址     2.服务器的端口号    3.会话连接的用户名和密码   4.服务器的用户名 ...

  4. (原创)不带模板的OLE输出EXCEL

    目前我已知的EXCEL输出方式有3种: 1.GUI_DOWNLOAD函数输出(适用于简单无格式要求的输出). 2.OLE输出(适用于对EXCEL格式输出有特殊要求的,但是因其填充数据和设置格式是基于一 ...

  5. node框架express

    见识到原生nodeJs服务器的恶心后,我们来用下简单好用的框架吧~ 服务器无非主要提供接口和静态文件读取,直接上代码: const express = require('express'); cons ...

  6. LeetCode & Q189-Rotate Array-Easy

    Array Description: Rotate an array of n elements to the right by k steps. For example, with n = 7 an ...

  7. Python扩展模块——调用WindowsAPI(pywin32的简单使用)

    这块使用的比较少,只用到了模拟键盘按键, 调用鼠标比较费事,是通过像素坐标实现的,如果没有特殊需求或万不得已不建议使用 import win32con import win32api win32api ...

  8. 解决SoapFault (looks like we got no XML document)问题

    今天在调试项目的时候出现下面的错误信息: SoapFault looks like we got no XML document (D:\phpStudy\WWW\self.shop.xunmall. ...

  9. 三十天学不会TCP,UDP/IP网络编程 -- RTT的计算

    欢迎去gitbook(https://www.gitbook.com/@rogerzhu/)看到完整版. 如果对和程序员有关的计算机网络知识,和对计算机网络方面的编程有兴趣,虽然说现在这种“看不见”的 ...

  10. shell:正则表达式和文本处理器

    1.什么是正则 正则就是用一些具有特殊含义的符号组合到一起(称为正则表达式)来描述字符或者字符串的方法.或者说:正则就是用来描述一类事物的规则. 生活中处处都是正则: 比如我们描述:4条腿 你可能会想 ...