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. 调整虚拟机中Linux的分辨率

    1 在虚拟机配置中,将显示的缓存提高,CPU也提高. 2 运行Linux,在system-preferences-display中调整分辨率

  2. SWD下载调试填坑,SWD连接丢失问题解决

    野火SWD下载器,设置好以后,第一次下载成功,莫名其妙丢失连接,发现在复位状态可以连接(惊奇) 网络上搜索到把Boot0和Boot1置高,就可以把程序下载到RAM里, 能下载以后就好办了,把程序里SW ...

  3. Mybatis中的关联映射和查询

    一.商品订单数据模型 1.数据表 这里定义了四个表,分别表示用户,商品,订单,和订单详情. 用户表user CREATE TABLE `user` ( `id` int(11) NOT NULL AU ...

  4. A visual proof that neural nets can compute any function

    http://neuralnetworksanddeeplearning.com/chap4.html In essence, we're using our single-layer neural ...

  5. IE模式下背景图片不显示

    初衷是想给这个提交按钮<input type="submit" value=" />加上背景图片,用了以下css样式: .subtn input { back ...

  6. 感知器(Perception)

    感知器是一种早期的神经网络模型,由美国学者F.Rosenblatt于1957年提出.感知器中第一次引入了学习的概念,使人脑所具备的学习功能在基于符号处理的数学到了一定程度模拟,所以引起了广泛的关注. ...

  7. sublime 添加 注释插件 Docblockr

    https://github.com/spadgos/sublime-jsdocs Package Control Open Package Control: Preferences -> Pa ...

  8. 改善程序与设计的55个具体做法 day4

    今天晚上回到小区门口,买了点冬枣,要结账的时候想起来,钥匙没带,落公司了! TNND,没办法再回趟公司,拿了钥匙,来回一个小时,汗~ 条款10:令operator=返回一个reference to * ...

  9. Java进阶学习:log4j的学习和使用

    Java进阶学习——log4j的学习和使用 简介Loj4j Log4j的组成 Log4j主要由三大组组件构成: Logger: 负责生成日志,并能够对日志信息进行分类筛选,通俗的讲就是决定什么日志信息 ...

  10. ThinkPHP 3.2.2 事务

    手册里说得非常清楚 : 5.3.19 事务支持 ThinkPHP提供了单数据库的事务支持,如果要在应用逻辑中使用事务,可以参考下面的方法: 启动事务: PHP代码 $User->startTra ...