出现次数很好处理,就是 \(right/endpos\) 集合的大小

那么,直接构建 \(SAM\)

求出每个位置的\(right\)集合大小

直接更新每个节点的\(longest\)就行了

最后短的可以由长的更新过来就好

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
using namespace std;
#define ll long long
#define RG register
#define MAX 2001000
inline int read()
{
RG int x=0,t=1;RG char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')t=-1,ch=getchar();
while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
return x*t;
}
char ch[MAX];
struct Node
{
int son[26];
int ff,len;
}t[MAX<<1];
int size[MAX];
int tot=1,last=1,c[MAX],a[MAX],ans[MAX];
void extend(int c)
{
int p=last,np=++tot;last=np;
t[np].len=t[p].len+1;
while(p&&!t[p].son[c])t[p].son[c]=np,p=t[p].ff;
if(!p)t[np].ff=1;
else
{
int q=t[p].son[c];
if(t[q].len==t[p].len+1)t[np].ff=q;
else
{
int nq=++tot;
t[nq]=t[q];
t[nq].len=t[p].len+1;
t[q].ff=t[np].ff=nq;
while(p&&t[p].son[c]==q)t[p].son[c]=nq,p=t[p].ff;
}
}
size[np]=1;
}
int main()
{
scanf("%s",ch+1);
int l=strlen(ch+1);
for(int i=1;i<=l;++i)extend(ch[i]-97);
for(int i=1;i<=tot;++i)c[t[i].len]++;
for(int i=1;i<=tot;++i)c[i]+=c[i-1];
for(int i=1;i<=tot;++i)a[c[t[i].len]--]=i;
for(int i=tot;i;--i)
{
int u=a[i];
size[t[u].ff]+=size[u];
ans[t[u].len]=max(ans[t[u].len],size[u]);
}
for(int i=l-1;i;--i)ans[i]=max(ans[i],ans[i+1]);
for(int i=1;i<=l;++i)printf("%d\n",ans[i]);
return 0;
}

【SPOJ】Substrings的更多相关文章

  1. 【SPOJ】Substrings(后缀自动机)

    [SPOJ]Substrings(后缀自动机) 题面 Vjudge 题意:给定一个长度为\(len\)的串,求出长度为1~len的子串中,出现最多的出现了多少次 题解 出现次数很好处理,就是\(rig ...

  2. 【SPOJ】Distinct Substrings(后缀自动机)

    [SPOJ]Distinct Substrings(后缀自动机) 题面 Vjudge 题意:求一个串的不同子串的数量 题解 对于这个串构建后缀自动机之后 我们知道每个串出现的次数就是\(right/e ...

  3. 【SPOJ】Distinct Substrings/New Distinct Substrings(后缀数组)

    [SPOJ]Distinct Substrings/New Distinct Substrings(后缀数组) 题面 Vjudge1 Vjudge2 题解 要求的是串的不同的子串个数 两道一模一样的题 ...

  4. 【SPOJ】Distinct Substrings

    [SPOJ]Distinct Substrings 求不同子串数量 统计每个点有效的字符串数量(第一次出现的) \(\sum\limits_{now=1}^{nod}now.longest-paren ...

  5. 【SPOJ】NUMOFPAL - Number of Palindromes(Manacher,回文树)

    [SPOJ]NUMOFPAL - Number of Palindromes(Manacher,回文树) 题面 洛谷 求一个串中包含几个回文串 题解 Manacher傻逼题 只是用回文树写写而已.. ...

  6. 【SPOJ】Longest Common Substring II (后缀自动机)

    [SPOJ]Longest Common Substring II (后缀自动机) 题面 Vjudge 题意:求若干个串的最长公共子串 题解 对于某一个串构建\(SAM\) 每个串依次进行匹配 同时记 ...

  7. 【SPOJ】Longest Common Substring(后缀自动机)

    [SPOJ]Longest Common Substring(后缀自动机) 题面 Vjudge 题意:求两个串的最长公共子串 题解 \(SA\)的做法很简单 不再赘述 对于一个串构建\(SAM\) 另 ...

  8. 【SPOJ】Power Modulo Inverted(拓展BSGS)

    [SPOJ]Power Modulo Inverted(拓展BSGS) 题面 洛谷 求最小的\(y\) 满足 \[k\equiv x^y(mod\ z)\] 题解 拓展\(BSGS\)模板题 #inc ...

  9. 【SPOJ】QTREE7(Link-Cut Tree)

    [SPOJ]QTREE7(Link-Cut Tree) 题面 洛谷 Vjudge 题解 和QTREE6的本质是一样的:维护同色联通块 那么,QTREE6同理,对于两种颜色分别维护一棵\(LCT\) 每 ...

随机推荐

  1. 在CI框架中的配置整合amfphp

    之前做的项目用到CI框架和amfphp的整合,主要用于php与flex的交互,在此做一下记录: 一. 安装CI框架: 1.  搭建PHP运行环境,本人在WIN7下用WAMP作测试,安装目录:d:/wa ...

  2. IDEA 设置忽略那些文件不提交到SVN服务器

  3. C/C++语法知识点汇总

    *  静态局部变量,在不同函数中可以同名. 静态全局变量,在不同文件中可以同名. 静态函数,在不同文件中可以同名. *  普通全局变量和普通函数,在同一工程中不能同名. 在相链接的程序与库之间,可以同 ...

  4. linux命令学习笔记(44):top命令

    top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管 理器.下面详细介绍它的使用方法.top是一个动态显示过程,即可以通过用户按键来不断刷 ...

  5. appium 支持输入中文

    加入: desired_caps['unicodeKeyboard'] = True desired_caps['resetKeyboard'] = True 使用输入中文: input_txt = ...

  6. ACM学习历程——HDU5015 233 Matrix(矩阵快速幂)(2014陕西网赛)

    Description In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 2 ...

  7. hdu3037Saving Beans——卢卡斯定理

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=3037 卢卡斯定理模板——大组合数的取模 代码如下: #include<iostream> #i ...

  8. BLE Mesh网络协议综述

    0 引言 自2012年蓝牙4.0规范推出之后,全新的蓝牙低功耗(BLE)技术由于其极低的运行和待机功耗.低成本和跨厂商互操作性,3 ms低延迟.AES-128加密等诸多特色,可以用于计步器.心律监视器 ...

  9. appium+python 快速给真机安装app

    #coding=utf-8from appium import webdriverfrom time import sleepimport os,time,unittest '''给手机快速装app的 ...

  10. 【248】◀▶IEW-Unit13

    Unit 13 Technology 流程图讲解 1.model1对应图片讲解 2.Model1范文分析 Model 1 The ice cream making process has five k ...