CF316G2.Good Substrings
提高+/省选-
通过率:0%
时间限制:4.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Smart Beaver recently got interested in a new word game. The point is as follows: count the number of distinct good substrings of some string s. To determine if a string is good or not the game uses rules. Overall there are n rules. Each rule is described by a group of three (p, l, r), where p is a string and l and r (l ≤ r) are integers. We’ll say that string t complies with rule (p, l, r), if the number of occurrences of string t in string p lies between l and r, inclusive. For example, string "ab", complies with rules ("ab", 1, 2) and ("aab", 0, 1), but does not comply with rules ("cd", 1, 2) and ("abab", 0, 1).
A substring s[l... r] (1 ≤ l ≤ r ≤ |s|) of string s = _s_1_s_2... s|s| (|s| is a length of s) is string s__l__s__l + 1... s__r.
Consider a number of occurrences of string t in string p as a number of pairs of integers l, r (1 ≤ l ≤ r ≤ |p|) such that p[l... r] = t.
We’ll say that string t is good if it complies with all n rules. Smart Beaver asks you to help him to write a program that can calculate the number of distinct good substrings of string s. Two substrings s[x... y] and s[z... w] are cosidered to be distinct iff s[x... y] ≠ s[z... w].
聪明的海狸最近对一种新的单词游戏产生了兴趣。游戏规则如下:统计字符串 s 中不同“好”子串的数量。要判断一个字符串是否为“好”串,需依据若干条规则。总共有 n 条规则,每条规则由一个三元组 (p,l,r) 描述,其中 p 是一个字符串,l 和 r(满足 l≤r)是整数。我们称字符串 t 符合规则 (p,l,r),当且仅当 t 在字符串 p 中的出现次数介于 l 与 r 之间(含端点)。例如,字符串 "ab" 符合规则 ("ab", 1, 2) 和 ("aab", 0, 1),但不符合规则 ("cd", 1, 2) 和 ("abab", 0, 1)。
字符串 s=s1s2…s∣s∣(其中 ∣s∣ 表示 s 的长度)的一个子串 s[l…r](满足 1≤l≤r≤∣s∣)定义为字符串 slsl+1…sr。
我们将字符串 t 在字符串 p 中的出现次数定义为满足 p[l…r]=t 的整数对 (l,r)(其中 1≤l≤r≤∣p∣)的个数。
若字符串 t 符合全部 n 条规则,则称其为好串。聪明的海狸请你帮他编写一个程序,计算字符串 s 中不同好子串的个数。两个子串 s[x…y] 与 s[z…w] 被视为不同,当且仅当 s[x…y]=s[z…w]。
输入格式
The first line contains string s. The second line contains integer n. Next n lines contain the rules, one per line. Each of these lines contains a string and two integers p__i, l__i, r__i, separated by single spaces (0 ≤ l__i ≤ r__i ≤ |p__i|). It is guaranteed that all the given strings are non-empty and only contain lowercase English letters.
The input limits for scoring 30 points are (subproblem G1):
- 0 ≤ n ≤ 10.
- The length of string s and the maximum length of string p is ≤ 200.
The input limits for scoring 70 points are (subproblems G1+G2):
- 0 ≤ n ≤ 10.
- The length of string s and the maximum length of string p is ≤ 2000.
The input limits for scoring 100 points are (subproblems G1+G2+G3):
- 0 ≤ n ≤ 10.
- The length of string s and the maximum length of string p is ≤ 50000.
第一行包含字符串 s。第二行包含整数 n。接下来的 n 行每行包含一条规则。每行包含一个字符串和两个整数 pi、li、ri,以单个空格分隔(满足 0 ≤ li ≤ ri ≤ ∣pi∣)。保证所有给定字符串均非空,且仅由小写英文字母组成。
得 30 分的输入限制(子问题 G1):
- 0 ≤ n ≤ 10。
- 字符串 s 的长度以及字符串 p 的最大长度均 ≤ 200。
得 70 分的输入限制(子问题 G1+G2):
- 0 ≤ n ≤ 10。
- 字符串 s 的长度以及字符串 p 的最大长度均 ≤ 2000。
得 100 分的输入限制(子问题 G1+G2+G3):
- 0 ≤ n ≤ 10。
- 字符串 s 的长度以及字符串 p 的最大长度均 ≤ 50000。
输出格式
Print a single integer — the number of good substrings of string s.
输出一个整数——字符串 s 中“好”子串的个数。
输入输出样例
输入#1
aaab 2 aa 0 0 aab 1 1
输出#1
3
输入#2
ltntlnen 3 n 0 0 ttlneenl 1 4 lelllt 1 1
输出#2
2
输入#3
a 0
输出#3
1
说明/提示
There are three good substrings in the first sample test: «aab», «ab» and «b».
In the second test only substrings «e» and «t» are good.
第一个样例测试中有三个“好”子串:«aab»、«ab» 和 «b»。
第二个测试中,仅有子串 «e» 和 «t» 是“好”的。
输入解题思路,AI测评打分。不知道怎么写?