vjudge

题意

给你一个串,求不同字串个数。

\(n\le10^5\)

sol

直接建SAM然后输出\(\sum_{i=1}^{tot}len[i]-len[fa[i]]\)

code

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1e5+5;
int T,n,last=1,tot=1,tr[N][26],fa[N],len[N];
char s[N];long long ans;
void extend(int c)
{
int v=last,u=++tot;last=u;
len[u]=len[v]+1;
while (v&&!tr[v][c]) tr[v][c]=u,v=fa[v];
if (!v) fa[u]=1;
else
{
int x=tr[v][c];
if (len[x]==len[v]+1) fa[u]=x;
else
{
int y=++tot;
memcpy(tr[y],tr[x],sizeof(tr[y]));
fa[y]=fa[x];fa[x]=fa[u]=y;len[y]=len[v]+1;
while (v&&tr[v][c]==x) tr[v][c]=y,v=fa[v];
}
}
}
int main()
{
scanf("%d",&T);
while (T--)
{
scanf("%s",s+1);n=strlen(s+1);
ans=0;last=tot=1;
memset(tr,0,sizeof(tr));
memset(fa,0,sizeof(fa));
memset(len,0,sizeof(len));
for (int i=1;i<=n;++i) extend(s[i]-'A');
for (int i=1;i<=tot;++i) ans+=len[i]-len[fa[i]];
printf("%lld\n",ans);
}
return 0;
}

[SPOJ-DISUBSTR]Distinct Substrings的更多相关文章

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

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

  2. SPOJ DISUBSTR Distinct Substrings 后缀数组

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

  3. DISUBSTR - Distinct Substrings

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

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

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

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

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

  6. 【SPOJ】Distinct Substrings

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

  7. SPOJ 694. Distinct Substrings (后缀数组不相同的子串的个数)转

    694. Distinct Substrings Problem code: DISUBSTR   Given a string, we need to find the total number o ...

  8. SPOJ 694 Distinct Substrings

    Distinct Substrings Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on SPOJ. O ...

  9. spoj694 DISUBSTR - Distinct Substrings

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

  10. SPOJ 694 Distinct Substrings/SPOJ 705 New Distinct Substrings(后缀数组)

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

随机推荐

  1. vue组件父子组件之间传递数据

    举个栗子: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...

  2. bash批量去前缀

    #!/bin/sh for aFile in *; do oldfile=`basename "$aFile"` newfile=${oldfile::} echo ${oldfi ...

  3. java Filter的简单使用

    java web中的过滤器的简单使用.直接上代码.1.web.xml <?xml version="1.0" encoding="UTF-8"?> ...

  4. ArcGIS API for js Legend(图例)

    1.说明 有关怎么把ArcGIS API for js部署到IIS上,请参考我上面的写的博客https://www.cnblogs.com/net064/p/10302660.html 2.运行效果 ...

  5. Js编写的菜单树

    只需要提供这种JSON格式就ok了 其他的都可以直接引用这个代码进去 var testMenu=[ { "name": "一级菜单", "submen ...

  6. HTTP 304 详解

    把Last-Modified 和ETags请求的http报头一起使用,这样可利用客户端(例如浏览器)的缓存.因为服务器首先产生 Last-Modified/Etag标记,服务器可在稍后使用它来判断页面 ...

  7. Cordova+FrameWork7开发简单教程

    1: 环境要有:(一个不会搭建环境的程序员,要么学,要么退出编程 ) 环境这里我只说需要什么: 1>AndroidStudio 3.0 (2.几的版本总会出问题.我喜欢用新版本) 2>co ...

  8. mysql设置指定ip远程访问连接的方法

    本文实例讲述了mysql设置指定ip远程访问连接的方法,分享给大家供大家参考.具体实现方法如下: 1. 授权用户root使用密码jb51从任意主机连接到mysql服务器: 复制代码 代码如下: GRA ...

  9. 数据库存储I/O类型分析与配置

    存储设备作为数据的容器,为应用提供数据存取服务,而存储系统将数据展现给不同的应用后,应用程序对数据访问不尽相同.简要来说,就是读和写,更加细分的话是以不同的传输单元(I/O大小)进行顺序和随机类型的读 ...

  10. linux 6-find,xargs

    十六. 文件查找命令find:     下面给出find命令的主要应用示例:     /> ls -l     #列出当前目录下所包含的测试文件     -rw-r--r--. 1 root r ...