后缀自动机

留个板子

upd:大概懂了 每次新加入的npRight集合肯定只有最后一个位置,那么求所有长得不一样的子串贡献就是Max-Min+1,因为Right集合只有这一个位置,所以这Max-Min+1个子串只出现在最后一个位置。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + ;
int n;
ll ans;
namespace SAM
{
int root, sz, last;
struct node {
int par, val;
map<int, int> ch;
} t[N];
int nw(int x) { t[++sz].val = x; return sz; }
void iniSAM() { sz = ; root = last = nw(); }
void extend(int c)
{
int p = last, np = nw(t[p].val + );
while(p && !t[p].ch[c]) t[p].ch[c] = np, p = t[p].par;
if(!p) t[np].par = root;
else
{
int q = t[p].ch[c];
if(t[q].val == t[p].val + ) t[np].par = q;
else
{
int nq = nw(t[p].val + );
t[nq].ch = t[q].ch;
t[nq].par = t[q].par;
t[q].par = t[np].par = nq;
while(p && t[p].ch[c] == q) t[p].ch[c] = nq, p = t[p].par;
}
}
ans += t[np].val - t[t[np].par].val;
last = np;
}
} using namespace SAM;
int main()
{
scanf("%d", &n);
iniSAM();
for(int i = ; i <= n; ++i)
{
int x;
scanf("%d", &x);
extend(x);
printf("%lld\n", ans);
}
return ;
}

最新文章

  1. Atitit.http代理的实现 代码java php c# python
  2. android audio无法自动播放
  3. imx6 关闭调试串口
  4. python时间函数学习
  5. cordova添加platform
  6. 编译android源码官方教程(4)开始编译
  7. iOS - CoreMotion
  8. 全栈式JavaScript
  9. List Comprehensions
  10. jsonp多次请求报错 not a function的解决方法
  11. 模块化手机project ara之我见
  12. Python之路-基本数据类型
  13. python http长连接客户端
  14. 通过Activity动态加载Fragment创建主界面构架
  15. 创建元素节点createElement
  16. Hibernate(五):Hibernate配置文件及C3P0的用法
  17. HTML4入门
  18. Autohotkey常用命令
  19. poj 3666 Making the Grade(离散化+dp)
  20. HDU 5225 枚举

热门文章

  1. Oracle EBS - 工单状态
  2. 【sourcetree】sourcetree连接远程仓库需要登陆但是一直登陆不上的问题 解决方法
  3. CVE-2014-4114 和 CVE-2014-3566
  4. 老大写得一个非常高大上的Makefile,包括非常多语法:
  5. 深入JVM系列(二)之GC机制、收集器与GC调优(转)
  6. 提高系统性能——对SQL语句优化的思考
  7. 图片3d轮放查看效果(V2.0):使用鼠标拖动实现图片的轮放
  8. 基本SQL 语句操作数据增删查改
  9. VS2013带来的&amp;quot;新特性&amp;quot;
  10. 基本SCTP套接字编程常用函数