#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 of length .
Meanwhile, the user has a dictionary containing words. Each word is a string, and the -th word is denoted by .
Next, define the find and replace feature:
-
Find: There are two parameters , asking for the sum, over every word in the dictionary, of the number of occurrences of in .
That is, compute $\displaystyle \sum_{i=1}^{m} \mathrm{occur}(s_i, a[l : r])$, where denotes the number of occurrences of string in string . -
Replace: There are three parameters , where is a string, meaning to replace with the result of repeating endlessly and taking the needed prefix.
For example, if we replace with the endlessly repeated string , then the original string becomes .
The user provides 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 , representing the length of the file , the number of words in the dictionary, and the number of queries.
The second line contains a string of length , representing the initial file.
The next lines each contain a string; the -th line is the -th word .
The next lines each describe an operation:
The first number on each line is , indicating the type of operation.
If , then two integers follow, meaning this is a find operation with parameters .
If , then two integers and a string follow, meaning this is a replace operation with parameters .
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): , all string lengths , time limit .
- Subtask 2 (7 points): , time limit .
- Subtask 3 (13 points): , time limit .
- Subtask 4 (17 points): There are no replace operations, i.e. , time limit .
- Subtask 5 (18 points): , , , time limit .
- Subtask 6 (13 points): , , , time limit .
- Subtask 7 (25 points): No special constraints, time limit .
For of the data:
Constraints on : , , .
Constraints on string lengths: , , .
All strings are guaranteed to be non-empty, and all characters belong to the set , 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 .
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 of length , the notation () denotes the substring of from to . That is, the string formed by concatenating the -th through the -th characters of s|s|$ denotes its length.
Translated by ChatGPT 5
京公网安备 11011102002149号