题面

字符串$ S \(最多包含\) 25 \(万个小写拉丁字母。我们将\) F(x) \(定义为长度为\) x \(的某些字符串出现在\) s \(中的最大次数。例如,对于字符串\) “ababa”\(,\)F(3) \(将为\) 2\(,因为存在两次出现的字符串\) “aba”\(。您的任务是为每个\) i $输出 \(F(i)\),以便$ 1 <= i < = |S|$

Sol

\(sam\)

直接求一下每个\(endpos(right)\)集合的子串出现次数

然后就没了

# include <bits/stdc++.h>
# define IL inline
# define RG register
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll; template <class Int>
IL void Input(RG Int &x){
RG int z = 1; RG char c = getchar(); x = 0;
for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
x *= z;
} const int maxn(5e5 + 5); int n, trans[26][maxn], fa[maxn], len[maxn], tot = 1, last = 1;
int id[maxn], t[maxn], size[maxn], ans[maxn];
char s[maxn]; IL void Extend(RG int c){
RG int p = last, np = ++tot; last = tot;
len[np] = len[p] + 1, size[np] = 1;
while(p && !trans[c][p]) trans[c][p] = np, p = fa[p];
if(!p) fa[np] = 1;
else{
RG int q = trans[c][p];
if(len[q] == len[p] + 1) fa[np] = q;
else{
RG int nq = ++tot;
fa[nq] = fa[q], len[nq] = len[p] + 1;
for(RG int i = 0; i < 26; ++i) trans[i][nq] = trans[i][q];
fa[q] = fa[np] = nq;
while(p && trans[c][p] == q) trans[c][p] = nq, p = fa[p];
}
}
} int main(RG int argc, RG char* argv[]){
scanf(" %s", s), n = strlen(s);
for(RG int i = 0; i < n; ++i) Extend(s[i] - 'a');
for(RG int i = 1; i <= tot; ++i) ++t[len[i]];
for(RG int i = 1; i <= tot; ++i) t[i] += t[i - 1];
for(RG int i = 1; i <= tot; ++i) id[t[len[i]]--] = i;
for(RG int i = tot; i; --i){
size[fa[id[i]]] += size[id[i]];
ans[len[id[i]]] = max(ans[len[id[i]]], size[id[i]]);
}
for(RG int i = tot; i; --i) ans[i] = max(ans[i], ans[i + 1]);
for(RG int i = 1; i <= n; ++i) printf("%d\n", ans[i]);
return 0;
}

SPOJ:NSUBSTR - Substrings的更多相关文章

  1. ●SPOJ 8222 NSUBSTR–Substrings

    题链: http://www.spoj.com/problems/NSUBSTR/题解: 后缀自动机. 不难发现,对于自动机里面的一个状态s, 如果其允许的最大长度为maxs[s],其right集合的 ...

  2. ●SPOJ 8222 NSUBSTR - Substrings(后缀数组)

    题链: http://www.spoj.com/problems/NSUBSTR/ 题解: 同届红太阳 --WSY给出的后缀数组解法!!! 首先用倍增算法求出 sa[i],rak[i],hei[i]然 ...

  3. ●SPOJ 8222 NSUBSTR–Substrings(后缀自动机)

    题链: http://www.spoj.com/problems/NSUBSTR/ 题解: 后缀自动机的水好深啊!懂不了相关证明,带着结论把这个题做了.看来这滩深水要以后再来了. 本题要用到一个叫 R ...

  4. SPOJ 8222 NSUBSTR - Substrings

    http://www.spoj.com/problems/NSUBSTR/ 题意: F(x)定义为字符串S中所有长度为x的子串重复出现的最大次数 输出F[1]~F[len(S)] 用字符串S构建后缀自 ...

  5. 【刷题】SPOJ 8222 NSUBSTR - Substrings

    You are given a string S which consists of 250000 lowercase latin letters at most. We define F(x) as ...

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

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

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

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

  8. 【SPOJ】Distinct Substrings

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

  9. SPOJ NSUBSTR Substrings 后缀自动机

    人生第一道后缀自动机,总是值得纪念的嘛.. 后缀自动机学了很久很久,先是看CJL的论文,看懂了很多概念,关于right集,关于pre,关于自动机的术语,关于为什么它是线性的结点,线性的连边.许多铺垫的 ...

随机推荐

  1. 1. Socket网络编程

    1. 借助服务器实现小写转大写的程序: 客户端:发送任意小写字母到服务器端. 服务器端:接收小写字母,转为大写,回传给客户端,然后客户端显示到屏幕. #include <stdio.h> ...

  2. E - Guess the Root 拉格朗日差值法+交互

    题目传送门 题意:告诉你存在一个未知项系数最高为10的$f(x)$,你最多可以有50次询问,每次询问给出一个$x'$,系统会返回你$f(x')$的值,你需要猜一个$x''$,使得$f(x'')=0$, ...

  3. service iptables xxx无效命令的情况下,如何启动/重启iptables

    最近在CentOS 7.6下使用service iptables xxx相关命令,提示如下错误:The service command supports only basic LSB actions ...

  4. 在windows上添加cygwin右键

    来了一台新机器,装环境的时候,突然想直接在右键使用cygwin. 查了一些教程,基本大同小异,也算是有用,先贴一个链接: https://blog.csdn.net/yang_hong_/articl ...

  5. excel 快速填充所有非连续空白单元格

    工作中经常会碰到这样的表,需要把空白的单元格填充完成.变成后图.下面就是方法.       工具/原料 EXCEL 方法/步骤   首先选中你要填充的区域,   按“F5"或者 Ctrl + ...

  6. 关闭mac自带apache的启动。

    关闭mac自带apache的启动. sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 如果哪天 ...

  7. MySQL error2003错误原因以及解决方案

    转自:http://hi.baidu.com/tianxia339/item/8e8849111461ea7e7a5f2540 出现ERROR 2003 (HY000): Can't connect ...

  8. linux mint 18.2 安装wireshark

    Method 1: Via PPA Step 1: Add the official PPA sudo add-apt-repository ppa:wireshark-dev/stable Step ...

  9. maven多模块下新建子模块

    选中parent模块,右键选择new---others 选择Maven---Maven Module,点击下一步 填写Module Name,其他默认,点击下一步 默认,下一步 默认,点击完成

  10. memcached 学习笔记 1

    一 简介 1 What is Memcached? Free & open source, high-performance, distributed memory object cachin ...