/*
统计每个节点的max和min, 然后求和即可
min = max[fa] + 1 */
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
#define ll long long
#define M 6010
#define mmp make_pair
using namespace std;
int read()
{
int nm = 0, f = 1;
char c = getchar();
for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
return nm * f;
}
int t, ch[M][26], len[M], fa[M], cnt, lst;
char s[M]; void insert(int c)
{
int p = ++cnt, f = lst;
len[p] = len[f] + 1;
lst = p;
while(f && !ch[f][c]) ch[f][c] = p, f = fa[f];
if(!f)
{
fa[p] = 1;
return;
}
int q = ch[f][c], nq = ++cnt;
if(len[f] + 1 == len[q])
{
fa[p] = q;
cnt--;
return;
}
len[nq] = len[f] + 1;
fa[nq] = fa[q];
fa[q] = fa[p] = nq;
memcpy(ch[nq], ch[q], sizeof(ch[nq]));
while(f && ch[f][c] == q) ch[f][c] = nq, f = fa[f];
} void init()
{
cnt = lst = 1;
memset(ch, 0, sizeof(ch));
memset(len, 0, sizeof(len));
memset(fa, 0, sizeof(fa));
} int main()
{
t = read();
while(t--)
{
init();
scanf("%s", s + 1);
int l = strlen(s + 1);
for(int i = 1; i <= l; i++) insert(s[i] - 'A');
int ans = 0;
for(int i = 1; i <= cnt; i++) ans += len[i] - len[fa[i]];
cout << ans << "\n";
}
return 0;
}

SP694 DISUBSTR - Distinct Substrings的更多相关文章

  1. DISUBSTR - Distinct Substrings

    DISUBSTR - Distinct Substrings no tags  Given a string, we need to find the total number of its dist ...

  2. spoj694 DISUBSTR - Distinct Substrings

    Given a string, we need to find the total number of its distinct substrings. Input T- number of test ...

  3. SPOJ - DISUBSTR Distinct Substrings (后缀数组)

    Given a string, we need to find the total number of its distinct substrings. Input T- number of test ...

  4. SPOJ DISUBSTR Distinct Substrings 后缀数组

    题意:统计母串中包含多少不同的子串 然后这是09年论文<后缀数组——处理字符串的有力工具>中有介绍 公式如下: 原理就是加上新的,减去重的,这题是因为打多校才补的,只能说我是个垃圾 #in ...

  5. SPOJ 694 DISUBSTR - Distinct Substrings

    思路 求本质不同的子串个数,总共重叠的子串个数就是height数组的和 总子串个数-height数组的和即可 代码 #include <cstdio> #include <algor ...

  6. SPOJ 694&&SPOJ705: Distinct Substrings

    DISUBSTR - Distinct Substrings 链接 题意: 询问有多少不同的子串. 思路: 后缀数组或者SAM. 首先求出后缀数组,然后从对于一个后缀,它有n-sa[i]-1个前缀,其 ...

  7. SPOJ Distinct Substrings(后缀数组求不同子串个数,好题)

    DISUBSTR - Distinct Substrings no tags  Given a string, we need to find the total number of its dist ...

  8. SPOJ - Distinct Substrings,求不同的字串个数!

    DISUBSTR - Distinct Substrings 题意:给你一个长度最多1000的字符串,求不相同的字串的个数. 思路:一个长度为n的字符串最多有(n+1)*n/2个,而height数组已 ...

  9. Distinct Substrings SPOJ - DISUBSTR 后缀数组

    Given a string, we need to find the total number of its distinct substrings. Input T- number of test ...

随机推荐

  1. 在浏览器中输入url回车之后会发生什么

    在浏览器中输入URL之后,浏览器会经历以下5个步骤: 1.解析URL 2.DNS域名解析 3.浏览器与网站建立TCP链接(三次握手) 4.请求和传输数据 5.浏览器渲染页面 一.解析URL 什么是ur ...

  2. zookeeper 图形化的客户端工具:ZooInspector

    查看Zookeeper中的数据,我们可以通过ZkCli.sh命令客户端查看,但是不太直观,因为Zookeeper本身数据是以树型结构存储组织的, 今天推荐一个实用的界面操作工具ZooInspector ...

  3. laravel 一表關聯二表,二表關聯三表,通過一表controller拿三表數據

    model 一表關聯二表 public function ordercode() { return $this->hasOne(\App\Models\OrderCode::class,'id' ...

  4. MySQL程序之mysqldump详解

    mysqldump命令详解 mysqldump是mysql用于转存储数据库的实用程序.它主要产生一个SQL脚本,其中包含从头重新创建数据库所必需的命令CREATE TABLE INSERT等 用法: ...

  5. NLB网路负载均衡管理

    相对于ARR来说,ARR算是应用级别的负载均衡方案,而NLB则是服务器级别的负载均衡方案.ARR只能做请求入口的消息分发服务,这样如果我们的消息分发服务器给挂掉,那么做再多的应用服务集群也都枉然. A ...

  6. Ribbon 使用入门

    Ribbon 是 Netflix 下的负载均衡项目,在集群中为各个客户端的通信提供支持,主要实现中间层应用程序的负载均衡,提供以下特性: 负载均衡器,可支持插拔式的负载均衡规则 对多种协议提供支持,例 ...

  7. camera-arm-RPI

    这个属于先收藏着,知道有个开源的东西. luvcview是一个开源项目,专注于UVC摄像头的测试,只要您的摄像头支持UVC驱动,即可使用luvcview测试程序,如何知道自己的摄像头是不是支持UVC驱 ...

  8. c++中计算程序执行时间

    #include<iostream> #include<time.h> using namespace std; int main() { clock_t t1 = clock ...

  9. 时间序列大数据平台建设(Time Series Data,简称TSD)

    来源:https://blog.csdn.net/bluishglc/article/details/79277455 引言在大数据的生态系统里,时间序列数据(Time Series Data,简称T ...

  10. windows安装mysql数据库并修改密码

    1.下载 MySQL Community Server https://dev.mysql.com/downloads/mysql/ 2.解压 如果想要让MySQL安装在指定目录,那么就将解压后的文件 ...