#P9281. [AGM 2023 资格赛] Nădlac
[AGM 2023 资格赛] Nădlac
Problem Description
On a grassland, a group of sheep stand in a line. The wool of these sheep comes in colors. From most liked to least liked, the order is:
Then, the following three types of events will happen:
1: Some sheep join the end of the line one by one.
2: Given a color sequence , among all distinct substrings of the current sheep sequence, convert each substring into a sequence of numbers according to the preference order (for example, red is and violet is ), and count those whose lexicographic order is less than or equal to the lexicographically largest substring of .
3: Given a set of colors , find the sum of lengths of all distinct substrings of the current sheep sequence that are composed only of colors in .
Input Format
The first line contains an integer , representing the number of events.
In the next lines, each line first contains a number indicating the event type, and then:
1: Input a sheep sequence . It is guaranteed that .
2: Input a color sequence .
3: Input a color set .
Each color is represented by the uppercase form of the first letter of the word.
Output Format
For each event of type 2 and type 3, output the answer.
6
1 GBIOOYBIOOYBB
2 R
3 O
1 OOO
2 R
3 O
OOYBB
3
OOO
6
Hint
Translated by ChatGPT 5