CF138E.Hellish Constraints
省选/NOI-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Katya recently started to invent programming tasks and prepare her own contests. What she does not like is boring and simple constraints. Katya is fed up with all those "N does not exceed a thousand" and "the sum of a__i does not exceed a million" and she decided to come up with something a little more complicated.
The last problem written by Katya deals with strings. The input is a string of small Latin letters. To make the statement longer and strike terror into the people who will solve the contest, Katya came up with the following set of k restrictions of the same type (characters in restrictions can be repeated and some restrictions may contradict each other):
- The number of characters _c_1 in a string is not less than _l_1 and not more than _r_1.
- ...
- The number of characters c__i in a string is not less than l__i and not more than r__i.
- ...
- The number of characters c__k in a string is not less than l__k and not more than r__k.
However, having decided that it is too simple and obvious, Katya added the following condition: a string meets no less than L and not more than R constraints from the above given list.
Katya does not like to compose difficult and mean tests, so she just took a big string s and wants to add to the tests all its substrings that meet the constraints. However, Katya got lost in her conditions and asked you to count the number of substrings of the string s that meet the conditions (each occurrence of the substring is counted separately).
卡佳最近开始自己设计编程题目并筹备自己的比赛。她不喜欢那些枯燥而简单的约束条件。卡佳早已厌倦了诸如“N 不超过 1000”以及“所有 ai 的总和不超过 106”之类的限制,于是决定设计一些更复杂的约束。
卡佳最新设计的题目涉及字符串。输入是一个由小写拉丁字母组成的字符串。为了使题面更长、并让参赛者感到畏惧,卡佳提出了如下 k 条同类型的约束(约束中出现的字符可以重复,且某些约束之间可能相互矛盾):
- 字符 c1 在字符串中出现的次数不少于 l1 且不多于 r1;
- …
- 字符 ci 在字符串中出现的次数不少于 li 且不多于 ri;
- …
- 字符 ck 在字符串中出现的次数不少于 lk 且不多于 rk。
然而,卡佳觉得这样仍然过于简单和明显,于是又额外添加了如下条件:一个字符串必须恰好满足上述列表中 不少于 L 条且不多于 R 条 的约束。
卡佳不喜欢构造困难而刁钻的测试数据,因此她直接取了一个很长的字符串 s,并希望将其中所有满足上述约束的子串全部加入测试数据中。不过,卡佳在一堆约束条件中迷失了方向,于是请你帮她计算字符串 s 中有多少个子串满足这些约束条件(每个子串的每次出现均单独计数)。
输入格式
The first line contains a non-empty string s, consisting of small Latin letters. The length of the string s does not exceed 105.
The second line contains three space-separated integers k, L and R (0 ≤ L ≤ R ≤ k ≤ 500).
Next k lines contain Katya's constrictions in the following form "c__i l__i r__i". All letters c__i are small Latin letters, l__i and r__i are integers (0 ≤ l__i ≤ r__i ≤ |s|, where |s| is the length of string s). Letters c__i are not necessarily different.
第一行包含一个非空字符串 s,由小写拉丁字母组成。字符串 s 的长度不超过 105。
第二行包含三个用空格分隔的整数 k、L 和 R(满足 0 ≤ L ≤ R ≤ k ≤ 500)。
接下来的 k 行描述 Katya 的约束条件,每行格式为 “ci li ri”。其中所有字母 ci 均为小写拉丁字母,li 和 ri 为整数(满足 0 ≤ li ≤ ri ≤ ∣s∣,其中 ∣s∣ 表示字符串 s 的长度)。字母 ci 不一定互不相同。
输出格式
Print a single number — the number of substrings that meet the constrictions.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cout stream or the %I64d specificator.
输出一个整数——满足约束条件的子串个数。
在 C++ 中,请勿使用 %lld 格式说明符读取或写入 64 位整数。推荐使用 cout 流或 %I64d 格式说明符。
输入输出样例
输入#1
codeforces 2 0 0 o 1 2 e 1 2
输出#1
7
输入#2
codeforces 2 1 1 o 1 2 o 1 2
输出#2
0
说明/提示
In the first test we should count the number of strings that do not contain characters "e" and "o". All such strings are as follows (in the order of occurrence in the initial string from the left to the right): "c", "d"', "f", "r", "rc", "c", "s".
In the second test we cannot achieve fulfilling exactly one of the two identical constrictions, so the answer is 0.
在第一个测试中,我们需要统计不包含字符 “e” 和 “o” 的字符串的数量。所有满足条件的字符串如下(按其在原字符串中从左到右出现的顺序):“c”、“d”、“f”、“r”、“rc”、“c”、“s”。
在第二个测试中,我们无法恰好满足两个相同约束条件中的一个,因此答案为 0。
输入解题思路,AI测评打分。不知道怎么写?