#P8451. [LSOT-1] Crosspain

[LSOT-1] Crosspain

Background

Problem Description

Let S0=S_0=\varnothing. Maintain a data structure that supports the following operations:

  • 1 hoc s: Let Si=Shoc{s}S_i=S_{hoc}\cup\{s\}, where ss is a string (it is guaranteed that before the operation sShocs\notin S_{hoc}).
  • 2 hoc s: Let Si=ShocS_i=S_{hoc}, and query the sum of the number of occurrences of all strings in SiS_i within the given string ss.

Input Format

The first line contains a positive integer qq, indicating the number of queries.

The next qq lines each contain one operation, in the format described above.

Output Format

For each operation 2, output one line containing the answer.

5
1 0 abc
2 0 abc
1 2 def
2 3 defg
2 1 abcd
0
1
1

Hint

Sample Explanation

In the third line, we ask how many times the strings in version 00 appear in abc. Since version 00 is empty, it appears 00 times.

In the fifth line, we ask how many times the strings in version 33 appear in defg. Since version 33 contains the string def, it appears 11 time.

In the sixth line, we ask how many times the strings in version 11 appear in abcd. Since version 11 contains the string abc, it appears 11 time.

Constraints and Notes

"This problem uses bundled testdata."

  • $\texttt{Subtask 1(10 pts):} \displaystyle \sum|s_i|\le 1000$.
  • Subtask 2(20 pts):\texttt{Subtask 2(20 pts):} All added strings have the same length.
  • Subtask 3(20 pts):\texttt{Subtask 3(20 pts):} All added strings contain only one kind of character.
  • Subtask 4(20 pts):q103\texttt{Subtask 4(20 pts):}q\le 10^3.
  • Subtask 5(30 pts):\texttt{Subtask 5(30 pts):} No special restrictions.

For all testdata, 1q5×1051\le q\le 5\times 10^5, 1isi106\displaystyle 1\le \sum_i|s_i|\le 10^6. All strings contain only lowercase letters.

Translated by ChatGPT 5