#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 77 colors. From most liked to least liked, the order is:

red>orange>yellow>green>blue>indigo>violetred>orange>yellow>green>blue>indigo>violet

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 TT, 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 77 and violet is 11), and count those whose lexicographic order is less than or equal to the lexicographically largest substring of TT.

3: Given a set of colors CC, find the sum of lengths of all distinct substrings of the current sheep sequence that are composed only of colors in CC.

Input Format

The first line contains an integer Q(1Q500)Q (1≤Q≤500), representing the number of events.

In the next QQ lines, each line first contains a number indicating the event type, and then:

1: Input a sheep sequence S(1S105)S(1≤|S|≤10^5). It is guaranteed that S105∑|S|≤10^5.

2: Input a color sequence T(1T105)T(1≤|T|≤10^5).

3: Input a color set C(1C7)C(1≤|C|≤7).

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