将每个串正着插入Trie A中,倒着插入Trie B中. 并求出每个串在A,B中的dfs序. 每次查询等价于查询在A中dfs序在[la,ra]之间,在B中dfs序在[lb,rb]之间的串的个数,用主席树维护即可. #include<cstdio> const int S=2000010,N=2010,M=N*22; char s[S],ch; int n,m,i,j,k,posa[N],posb[N],g[S],v[N],nxt[N],ed,la,lb,ra,rb,ans; inline vo…
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3483 [题目大意] 给出一些串,同时给出m对前缀后缀,询问有多少串满足给出的前缀后缀模式, 题目要求强制在线 [题解] 我们对于给出的每个字符串正着插入字典树A,倒着插入字典树B, 对于一个前缀来说,在字典树A上得到的dfs序[st,en]就是所有的匹配串, 同理,后缀在字典树B上dfs序[st,en]表示所有的后缀匹配串, 同时满足两者的需提供二维查询,因此我们以Adfsn为版本,…
转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud D. Prefixes and Suffixes You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≤ i ≤ j…
题目连接:Codeforces 432D Prefixes and Suffixes 题目大意:给出一个字符串,求全部既是前缀串又是后缀串的字符串出现了几次. 解题思路:依据性质能够依据KMP算法求出全部的前后缀串,然后利用dp求解,dp[i]表示从1到i这个子串出现过的次数. 转移方程dp[jump[i]]+=dp[i]. 随意一个dp[i]的初始状态应该是1. #include <cstdio> #include <cstring> const int N = 1e5+5; i…
D. Prefixes and Suffixes time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce s…
用扩展KMP做简单省力..... D. Prefixes and Suffixes time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character.…
题目链接:Prefixes and Suffixes 题意:给定未知字符串长度n,给出2n-2个字符串,其中n-1个为未知字符串的前缀(n-1个字符串长度从1到n-1),另外n-1个为未知字符串的后缀(n-1个字符串长度从1到n-1),判断这2n-2个字符串分别为前缀还是后缀. 题解:从2n-2从找个n-1长度的字符串和1长度的字符串拼接,判断该字符串是否符合要求,能作为未知字符串.符合的话,直接输出答案. #include <set> #include <map> #includ…
http://codeforces.com/contest/1092/problem/C Ivan wants to play a game with you. He picked some string ss of length nn consisting only of lowercase Latin letters. You don't know this string. Ivan has informed you about all its improper prefixes and s…
手动转田神的大作:http://blog.csdn.net/tc_to_top/article/details/38793973 D. Prefixes and Suffixes time limit per test 1:second memory limit per test: 256 megabytes input: standard input output: standard output You have a string s = s1s2...s|s|, where |s| is…
                                                    D. Prefixes and Suffixes You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≤ i ≤ j ≤ |s|)…