#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e6+10;
typedef long long ll;
char s[MAXN];
int n,siz[MAXN<<1];
ll ans=0;
const int inf=1e8;
struct SuffixTree{
int link[MAXN<<1],len[MAXN<<1],start[MAXN<<1],s[MAXN<<1];
int n,tail,now,rem,ch[MAXN<<1][27];
SuffixTree(){tail=1,n=0,rem=0,now=1,len[0]=inf;}
int newnode(int st,int le){
link[++tail]=1;start[tail]=st;len[tail]=le;return tail;
/*build new node
link->1,start=st(have been known)
len->le have been known
tail is the new number*/
}
void Extend(int x){
s[++n]=x;rem++;
/*add len(n),add rem
n->all strings' number
rem->now length(not the waited suffixstrings
suffixstrings is showed by "rem" & "now"
start[u]&len[u]:
is meaning of u's father is s[start[u]->start[u]+len[u]-1]*/
for(int last=1;rem;){
while(rem>len[ch[now][s[n-rem+1]]])
rem-=len[now=ch[now][s[n-rem+1]]];
/*
find the edge which the head is s[n-rem+1]
because that len(rem) may bigger than this edge's len
so we should del it's len and jump to the next
this is the setp2.
*/
int &v=ch[now][s[n-rem+1]];int c=s[start[v]+rem-1];
/*
v->the edge's last point
c->this edge's last character
*/
if(!v||x==c){
link[last]=now;last=now;
if(!v)v=newnode(n,inf);
/*
if there is no edge which is follow the rule
or,2 step is failed
then we should add the "suffix link"->link[last]=now,last=now
*/
else break;
/* if we find this edge is being,also
the last character have been there
it's meaning that we needn't to add now's character
so,we should break.
*/
}
else{
// if the last character is not being
int u=newnode(start[v],rem-1);
// build a new node,and split this edge
ch[u][c]=v;ch[u][x]=newnode(n,inf);
/*
u->have two points:one is v->inherit the before
and the other one is x:insert x.
*/
start[v]+=rem-1;len[v]-=rem-1;
/*
also,because we split this road
v's start and len should be updated
start+=rem-1,also the len[v] should cut rem-1
*/
link[last]=v=u;last=u;
//build lead to update the suffix link.
}
if(now==1)rem--;
/*
root is 1
if now=1,rem should be less
*/
else now=link[now];
/*
else,in order to add the next character,we should jump to the now's suffix link.
the meaning of suffix link is making find the next right edge and updating it more convenient and faster.
*/
}
}
}sft;
int dfs(int u,int dep){
if(dep>=inf)return 1;
siz[u]=0;
for(int i=0;i<=26;++i){
if(sft.ch[u][i]){
/*
if we can jump this edge
then,we continue to dfs and update the siz
*/
int d=dfs(sft.ch[u][i],dep+sft.len[sft.ch[u][i]]);
siz[u]+=d;
}
}
if(siz[u]>=2)ans=max(ans,1LL*siz[u]*dep);//the problem's querying
return siz[u];
}
int main(){
scanf("%s",s+1);
int n=strlen(s+1);
for(int i=1;i<=n;++i)s[i]-='a',sft.Extend(s[i]);//Extend the string
sft.Extend(26);//End character
dfs(1,0);//add up the answer
printf("%lld\n",ans);
}

\(\text{The code has explained by English.And the explaining will be updated after the High school entrance examination}\)

【暂咕咕咕】SuffixTree的更多相关文章

  1. (转)S5pv210 HDMI 接口在 Linux 3.0.8 驱动框架解析 (By liukun321 咕唧咕唧)

    作者:liukun321 咕唧咕唧 日期:2014.1.18 转载请标明作者.出处:http://blog.csdn.net/liukun321/article/details/18452663 本文 ...

  2. u-boot for tiny210 ver1.0(by liukun321咕唧咕唧)

     新版本下载: 下面的链接提供了较新版本的源码 ver4.0源码下载:u-boot for tiny210 ver4.0 ver3.1源码下载: u-boot for tiny210 ver3.1 v ...

  3. 基于S5pv210流媒体server的实现之网络摄像头(by liukun321 咕唧咕唧)

    这里仅介绍流媒体server端的实现思路.及编码注意问题,不会贴代码的详细实现. 直接入正题先介绍一下系统硬件框架: server端连接PC机用VLC播放例如以下图: server端应用程序能够分为图 ...

  4. linux多线程驱动中调用udelay()对整个系统造成的影响(by liukun321咕唧咕唧)

    以前没考虑过这个问题,而且之前可能运气比较好,虽然用了udelay但也没出什么奇怪的问题,今天在 CSDN上看到了一篇关于此问题帖子,觉得很受用,再此做简要的记录和分析: 驱动开的是内核线程 跟普通进 ...

  5. FT5X06 如何应用在10寸电容屏(linux-3.5电容屏驱动简析&移植10寸电容屏驱动到Android4.2) (by liukun321咕唧咕唧)

    这是几个月以前的东西了,在彻底遗忘之前拿出来好好写写.做个笔记,也算是造福后来人了.在做这个项目之前,没有做过电容屏的驱动,印象中的电容触摸屏是不需要校正的.IC支持多大的屏就要配多大的屏.但是拿到需 ...

  6. S5pv210 HDMI 接口在 Linux 3.0.8 驱动框架解析

    作者:liukun321 咕唧咕唧 日期:2014.1.18 转载请标明作者.出处:http://blog.csdn.net/liukun321/article/details/18452663 本文 ...

  7. 聊聊GIS中的坐标系|再版

    本文约6500字,建议阅读时间15分钟. 作者:博客园/B站/知乎/csdn/小专栏 @秋意正寒 版权:转载请告知,并在转载文上附上转载声明与原文链接(https://www.cnblogs.com/ ...

  8. [zt]给你的Mp4大换血,精选Touch里3年收集的900多首歌,"经典不忍去的""最新近流行的",与你共享~~

    如果你是音乐爱好者: 这些歌, 请戴上耳机, 调大音量, 一个人听 ,全世界 都是你的!!!!! (一)这些歌很温暖,没有金属味,适合有阳光的午后,很悠闲... [Anaesthesia]Maximi ...

  9. 关于Yaffs2在u-boot中的支持

    开发板是一块2G的MLC的NandFlash,页大小8k+512,为其移植u-boot到yaffs2这了.以前在Mini2440上移植过2k+64的slc的NandFlash的Yaffs2支持,当然也 ...

随机推荐

  1. xml selectnodes

    [xML ]SelectNodes的用法 之前简单找个SelectNodes的例子看了看,写了读取XML文件节点的程序,但是节点数目有限制,后来仔细看看,是自己没完全弄清SelectNodes的用法, ...

  2. oracle 11g 导入表时 提示 ***值太大错误

    导入数据库时,总是提示**值太大,实际值是**的错误. 具体忘了错误代码是什么了 ——! 经查询,这个是由于字符集设置的不是gbk的,导致导入时遇到中文字符出现的问题, 解决方法: 如果可以的话就把数 ...

  3. 干货:不同场景容器内获取客户端源IP的方法

    摘要:客户端和容器服务器之间可能存在多种不同形式的代理服务器,那容器中如何获取到客户端真实的源ip呢? k8s已经成为当今容器化的标准,人们在享受容器带来的高效与便利的同时,也遇到一些烦恼:客户端和容 ...

  4. SpringMVC执行流程源码分析

    SpringMVC执行流程源码分析 我们先来看张图片,帮助我们理解整个流程 然后我们开始来解析 首先SpringMVC基于Servlet来运行 那么我们首先来看HttpServletBean这个类 他 ...

  5. 痞子衡嵌入式:IVT里的不同entry设置可能会造成i.MXRT1xxx系列启动App后发生异常跑飞

    大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家分享的是IVT里的不同entry设置可能会造成i.MXRT1xxx系列启动App后发生异常跑飞问题的分析解决经验. 事情缘起恩智浦官方论坛上的一 ...

  6. 论文阅读:Relation Structure-Aware Heterogeneous Information Network Embedding

    Relation Structure-Aware Heterogeneous Information Network Embedding(RHINE) (AAAI 2019) 本文结构 (1) 解决问 ...

  7. appium的基本环境配置

    1.先安装jdk1.7或jdk1.8之后,并配置好环境变量 2.安装Android SDK(安卓软件开发包),测试Android手机必然要安装Android SDK,例如android-sdk_r24 ...

  8. C#类库推荐 拼多多.Net SDK,开源免费!

    背景介绍 近两年拼多多的发展非常迅速,即便口碑一般,也没有网页端,奈何我们已经全面小康,6亿月收入1000以下,9亿月收入2000以下,所以因为价格原因使用拼多多的用户也越来越多了.同样的,拼多多也开 ...

  9. C#调用Power Shell 管理Office365 执行脚本时遇到的问题

    Power Shell管理Office参考http://www.mamicode.com/info-detail-494553.html C#调用Power Shell 参考 https://www. ...

  10. Linux常用命令详解(1)

    基础命令:lsmanpwdcdmkdirechotouchcpmvrmrmdircatmorelessheadtailclearpoweroffreboot进阶命令(下一章节):aliasunalia ...