#P5599. 【XR-4】文本编辑器

【XR-4】文本编辑器

Description

Little X is building a text editor and now needs to implement the most basic “find and replace” feature.

In the text editor, the file is stored as a string aa of length nn.

Meanwhile, the user has a dictionary containing mm words. Each word is a string, and the ii-th word is denoted by sis_i.

Next, define the find and replace feature:

  • Find: There are two parameters l,rl, r, asking for the sum, over every word sis_i in the dictionary, of the number of occurrences of sis_i in a[l:r]a[l : r].
    That is, compute $\displaystyle \sum_{i=1}^{m} \mathrm{occur}(s_i, a[l : r])$, where occur(s,t)\mathrm{occur}(s, t) denotes the number of occurrences of string ss in string tt.

  • Replace: There are three parameters l,r,tl, r, t, where tt is a string, meaning to replace a[l:r]a[l : r] with the result of repeating tt endlessly and taking the needed prefix.
    For example, if we replace Mds72SKsLL\texttt{Mds72SKsLL} with the endlessly repeated string Rabb\texttt{Rabb}, then the original string becomes RabbRabbRa\texttt{RabbRabbRa}.

The user provides qq operations, each being either find or replace. You need to output the correct answer for every find operation.

Input Format

The first line contains three integers n,m,qn, m, q, representing the length of the file aa, the number of words in the dictionary, and the number of queries.

The second line contains a string aa of length nn, representing the initial file.

The next mm lines each contain a string; the ii-th line is the ii-th word sis_i.

The next qq lines each describe an operation:
The first number on each line is op\mathrm{op}, indicating the type of operation.
If op=1\mathrm{op} = 1, then two integers l,rl, r follow, meaning this is a find operation with parameters l,rl, r.
If op=2\mathrm{op} = 2, then two integers l,rl, r and a string tt follow, meaning this is a replace operation with parameters l,r,tl, r, t.

Output Format

For each find operation, output one integer per line, representing the answer to this find query.

6 2 5
BBABBA
BB
BAB
1 1 6
2 3 5 A
1 2 3
2 1 6 B
1 1 5

3
0
4

Hint

This problem uses bundled testdata.

  • Subtask 1 (7 points): n,m,q50n, m, q \le 50, all string lengths 50\le 50, time limit 1s1\text{s}.
  • Subtask 2 (7 points): n,q3000n, q \le 3000, time limit 1s1\text{s}.
  • Subtask 3 (13 points): m=1m = 1, time limit 2s2\text{s}.
  • Subtask 4 (17 points): There are no replace operations, i.e. op=1\mathrm{op} = 1, time limit 2s2\text{s}.
  • Subtask 5 (18 points): n,q8×104n, q \le 8 \times 10^4, si50\displaystyle \sum |s_i| \le 50, t8×104\displaystyle \sum |t| \le 8 \times 10^4, time limit 1s1\text{s}.
  • Subtask 6 (13 points): n,q5×104n, q \le 5\times 10^4, si5×104\displaystyle \sum |s_i| \le 5\times 10^4, t5×104\displaystyle \sum |t| \le 5\times 10^4, time limit 1s1\text{s}.
  • Subtask 7 (25 points): No special constraints, time limit 2s2\text{s}.

For 100%100\% of the data:
Constraints on n,m,q,l,r,opn, m, q, l, r, \mathrm{op}: 1lrn1061 \le l \le r \le n \le 10^6, 1m,q1051 \le m, q \le 10^5, op{1,2}\mathrm{op} \in \{ 1, 2 \}.
Constraints on string lengths: si50|s_i| \le 50, si2×105\displaystyle \sum |s_i| \le 2 \times 10^5, t106\displaystyle \sum |t| \le 10^6.
All strings are guaranteed to be non-empty, and all characters belong to the set Σ\mathbf{\Sigma}, where $\mathbf{\Sigma} = [\texttt a, \texttt z] \cup [\texttt A, \texttt Z] \cup [\texttt 0, \texttt 9]$, i.e. all lowercase letters, uppercase letters, and digits, so Σ=62|\mathbf{\Sigma}| = 62.

A special note: Compared to the file, the words are very short. You may need to make use of this when solving the problem.


[Some definitions]

For a string ss of length len\mathrm{len}, the notation s[l:r]s[l : r] (1lrlen1 \le l \le r \le \mathrm{len}) denotes the substring of ss from ll to rr. That is, the string formed by concatenating the ll-th through the rr-th characters of s(inclusive)inorder.Forastrings (inclusive) in order. For a string s,thenotation, the notation |s|$ denotes its length.

Translated by ChatGPT 5