#P4465. [国家集训队] JZPSTR

[国家集训队] JZPSTR

Description

You need to perform three types of operations on a string: 0. Insert a string yiy_i at position xix_i.

  1. Delete the substring in the interval [xi,yi)[x_i, y_i).
  2. Query how many times a given substring ziz_i occurs in the substring of the interval [xi,yi)[x_i, y_i).

The indices of the string start from 00 (that is, the first character has index 00).

Initially, the string is empty.

For the insertion operation, after insertion the first character of yiy_i should have index xix_i. For the deletion operation, the interval [xi,yi)[x_i, y_i) is a left-closed, right-open interval. For the query operation, the interval [xi,yi)[x_i, y_i) is a left-closed, right-open interval.

All inserted strings and query strings are non-empty and contain only characters 09\texttt{0}\sim\texttt{9}.

All query intervals and deletion intervals are non-empty.

The input is guaranteed to be valid.

If you do not understand the term "left-closed, right-open interval", please see the sample explanation.

Input Format

The first line contains an integer TT, the number of operations.

In the following TT lines, the first number pip_i indicates the type of the operation:

  • If pi=0p_i=0, then an integer xix_i and a string yiy_i follow, indicating an insertion.
  • If pi=1p_i=1, then two integers xix_i and yiy_i follow, indicating a deletion.
  • If pi=2p_i=2, then two integers xix_i and yiy_i, and a string ziz_i follow, indicating a query.

Output Format

For each query operation, output one line with the answer to that query.

8
0 0 894894894
2 0 2 894
2 0 9 894
0 2 6
2 0 9 64
2 0 9 894
1 2 6
2 0 6 894
0
3
1
1
2

Hint

Sample explanation:

  • After the first operation, the string is 894894894\texttt{894894894}.
  • In the second operation, the queried interval is 89\texttt{89}, which contains no 894\texttt{894}.
  • In the third operation, the queried interval is 894894894\texttt{894894894}, which contains three 894\texttt{894}.
  • After the fourth operation, the string is 8964894894\texttt{8964894894}.
  • In the fifth operation, the queried interval is 896489489\texttt{896489489}, which contains one 64\texttt{64}.
  • In the sixth operation, the queried interval is 896489489\texttt{896489489}, which contains one 894\texttt{894}.
  • After the seventh operation, the string is 894894\texttt{894894}.
  • In the eighth operation, the queried interval is 894894\texttt{894894}, which contains two 894\texttt{894}.

Constraints:

  • In 50%50\% of the testdata, the number of queries 100\le 100 (not the number of operations).
  • In 100%100\% of the testdata, the total inserted length 2×106\le 2\times 10^6, the string length at any time 106\le 10^6, the number of insertions 1001\le 1001, the number of deletions 1000\le 1000, and the total length of all queried ziz_i 104\le 10^4.

Source: 2012 CTT internal contest, by gyz.

Translated by ChatGPT 5