#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. Ingress-nginx 与 Nginx-ingress

    一.概述 Ingress-nginx:它是由Kubernetes社区基于Nginx Web服务器开发的,并补充了一组用于实现额外功能的Lua插件,作为“官方”默认控制器支持当然最优. Github:h ...

  2. codeforces 1262D Optimal Subsequences 主席树询问第k小

    题意 给定长度为\(n\)的序列\(a\),以及m个询问\(<k,pos>\),每次询问满足下列条件的子序列中第\(pos\)位的值为多少. 子序列长度为\(k\) 序列和是所有长度为\( ...

  3. Spark3.0YarnCluster模式任务提交流程源码分析

    1.通过spark-submit脚本提交spark程序 在spark-submit脚本里面执行了SparkSubmit类的main方法 2.运行SparkSubmit类的main方法 3.调用doSu ...

  4. php中的加密解密模块-mcrypt

    <?php /* 打开加密算法和模式 */ $td = mcrypt_module_open('rijndael-256', '', 'ofb', ''); /* 创建初始向量,并且检测密钥长度 ...

  5. 0 mysql 安装

    1 安装网址 https://dev.mysql.com/downloads/installer/ 选择 mysql server版本一路next 2.配置环境 mysql 默认安装位置是: C:\P ...

  6. JsonAnalyzer2 1.01版

    本版的改进主要在字符串的处理,前版不允许出现[]{},:等,现在都可以了,做出的修改主要在Lexer类,另外Token类增加1了下标,TreeBuilder类的不合语法处也做出一定修改. 测试用例:h ...

  7. Java清空一个指定文件

    清空test.log文件所有内容 File log = new File("c:\\test\\test.log"); FileWriter fileWriter =new Fil ...

  8. HTML模仿实现京东登录页面

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. 一文说清 InnoDB 的事务机制

    我们从一个转账的故事开始. 隔壁小王从美团上找到了一家水饺店,准备中午吃水饺.下单成功,支付20元. 商家这里响了一下:叮叮,您有美团外卖新订单啦,请及时处理.水饺一份,好嘞,下锅. 很快小王吃到外卖 ...

  10. 【小白学PyTorch】9 tensor数据结构与存储结构

    文章来自微信公众号[机器学习炼丹术]. 上一节课,讲解了MNIST图像分类的一个小实战,现在我们继续深入学习一下pytorch的一些有的没的的小知识来作为只是储备. 参考目录: @ 目录 1 pyto ...