Finding strings

5

3 votes
Advanced Data Structures, Data Structures, String Algorithms, Lazy Propagation in Interval/Segment Trees, Hashing algorithm
Problem

You are given an array A of N strings and Q operations where each operation is one of the following two types:

  1. A L R S: Appending string S to the subarray of strings [AL,AL+1,...AR1,AR]
  2. ? L R T: Finding the frequency of the string in subarrays [AL,AL+1,...AR1,AR]

Input format

  • The first line contains two integers N and Q which is the length of A and the number of operations respectively.
  • The second line contains N space-separated strings describing the content of A.
  • Each of the next Q lines contain the descriptions of each operation. 

Output format

For each operation of the second type, print the answer in a separate line.

Constraints

1 ≤ N ≤ 105

1 ≤ Q ≤ 105

1 ≤ L ≤ R ≤ N

1|Ai|,|T|,|S|105, where 1 ≤ i ≤ N

  • It is guaranteed that the total sum of lengths of the input strings does not exceed 1e6 characters and all input characters are lowercase English characters.
  • It is guaranteed that there is at least one and at most a hundred operations of the second type.
Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation
  • Input array A after first operation: [abca, baca, ab, abca, abcaba]
  • Input array A after first operation: [abcaba, bacaba, abba, abcaba, abcaba]
  • Now we can see that the frequency of the input string "abcaba" of the third operation is 3.
  • Now we can see that the frequency of the input string "abba" of the fourth operation is 1.

 

Editor Image

?