Little Daniel loves to play with strings! He always finds different ways to have fun with strings! Knowing that, his friend Kinan decided to test his skills so he gave him a string S and asked him Q questions of the form: If all distinct substrings o…
传送门[洛谷] 心态崩了我有妹子 靠 我写的记忆化搜索 莫名WA了 然后心态崩了 当我正要改成bfs排序的时候 我灵光一动 md我写的i=0;i<25;i++??? 然后 改过来就A掉了T^T 大体做法就是 一个点出发的本质不同子串数量应该是就是所有添加字符的转移和其余选一个空串的转移 所以直接建出自动机然后 我的做法是直接记忆化搜索就可以省去建树/排序 因为所有子串必定由转移构成 所以可以直接记忆化 附代码.(我觉得这个做法巨强无比) #include<cstdio> #include…
SUBLEX - Lexicographical Substring Search Little Daniel loves to play with strings! He always finds different ways to have fun with strings! Knowing that, his friend Kinan decided to test his skills so he gave him a string S and asked him Q questions…
题目传送门 传送门I 传送门II 题目大意 给定一个字符串,多次询问它的第$k$大本质不同的子串,输出它. 考虑后缀Trie.依次考虑每个后缀新增的本质不同的子串个数,显然,它是$n - sa[i] - height[i]$. 求出$height$数组后,求一求本质不同的子串个数的前缀和,可以对每个询问二分. 这里可以直接离线,$O(n + m)$扫一扫就好了. Code /** * SPOJ * Problem#SUBLEX * Accepted * Time: 30ms * Memory:…
SPOJ.com - Problem SUBLEX 这么裸的一个SAM,放在了死破OJ上面就是个坑. 注意用SAM做的时候输出要用一个数组存下来,然后再puts,不然一个一个字符输出会更慢. 还有一个就是不要多数据输入,估计最后多了几个没用的数字,反正我这么做一直无端端的RE.(就这样浪费了我一天好么!出数据的人这么不负责!) 最后就是,第k大的k是会超过子串数的.(这什么脑残配置?) 综上,这题除了坑就是坑. 代码如下: #include <bits/stdc++.h> using name…
题面 第一行给定主串\((len<=90000)\) 第二行给定询问个数\(T<=500\) 随后给出\(T\)行\(T\)个询问,每次询问排名第\(k\)小的串,范围在\(int\)内 相同的子串算一个 Sol \(sam\)中每条从起点出发的路径都对应一个子串 设\(f[i]\)表示从\(i\)出发的路径的条数 \(f[i]=1+\sum_{j\in trans[i]}f[j]\) 最后贪心一遍就好了 # include <bits/stdc++.h> # define IL…
\(\color{#0066ff}{ 题目描述 }\) 给定一个字符串,求排名第k小的串 \(\color{#0066ff}{输入格式}\) 第一行给定主串(len<=90000) 第二行给定询问个数T<=500 随后给出T行T个询问,每次询问排名第k小的串,范围在int内 \(\color{#0066ff}{输出格式}\) 对于每一个询问,输出T行,每行为排名第k小的串 \(\color{#0066ff}{输入样例}\) aaa 2 2 3 \(\color{#0066ff}{输出样例}\)…
Dicription Little Daniel loves to play with strings! He always finds different ways to have fun with strings! Knowing that, his friend Kinan decided to test his skills so he gave him a string S and asked him Q questions of the form: If all distinct s…
先求出SAM,然后考虑定义,点u是一个right集合,代表了长为dis[son]+1~dis[u]的串,然后根据有向边转移是添加一个字符,所以可以根据这个预处理出si[u],表示串u后加字符能有几个本质不同子串 然后回答的时候在树上跑一下即可 #include<iostream> #include<cstdio> #include<cstring> using namespace std; const int N=300005; int n,m,fa[N],ch[N][…
传送门 解题思路 首先建\(sam\),然后在拓扑序上\(dp\)一下,把每个点的路径数算出来,然后统计答案时就在自动机上\(dfs\)一下,仿照平衡树那样找第\(k\)小. 代码 #include<iostream> #include<cstdio> #include<cstring> #include<cmath> using namespace std; const int MAXN = 90005; inline int rd(){ int x=0,…