#P7204. [COCI 2019/2020 #3] Grudanje
[COCI 2019/2020 #3] Grudanje
Description
Patrik decided to redefine "perfect word": for the substrings of a word of length , if the parts of the substrings that are not covered by snow have no repeated letters, then the original word is called a "perfect word".
He wants to know after Krešimir has thrown how many snowballs the original word becomes a "perfect word".
Input Format
The first line contains a word consisting only of lowercase English letters, with length .
The second line contains an integer .
The next lines each contain two integers . This means the -th substring is taken as a continuous segment from the -th letter to the -th letter of the original word.
The next line contains pairwise distinct integers .
Output Format
Output the answer Patrik wants to know, i.e., after throwing how many (possibly ) snowballs the original word can become a "perfect word".
aaaaa
2
1 2
4 5
2 4 1 5 3
2
abbabaab
3
1 3
4 7
3 5
6 3 5 1 4 2 7 8
5
abcd
1
1 4
1 2 3 4
0
Hint
Sample Explanation
In the second sample, the word after being hit by snowballs one by one is:
abbab*ab
ab*ab*ab
ab*a**ab
*b*a**ab
*b****ab
******ab
*******b
********
Constraints
For of the testdata, .
For another of the testdata, .
For another of the testdata, the original word contains only the letter a.
For of the testdata, , , .
Notes
The score of this problem follows the original COCI setting, with a full score of .
Since on average each test point is worth points, half of the test points are set to points and the other half are set to points.
This problem is translated from COCI2019-2020 CONTEST #3 T2 Grudanje.
Translated by ChatGPT 5
京公网安备 11011102002149号