Christmas queries
Practice
0 (0 votes)
Algorithms
Hard
Approved
String
Hashing algorithm
Problem
89% Success 1238 Attempts 50 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Little Santa has a list S of names of N nice children and another list P of names of M naughty children. He doesn't want the names of nice children to get mixed with the naughty ones. Little Santa himself is naughty. He is making some changes in the names of naughty children. He can perform three type of queries:

  1. 1 id pos c: 1 denotes that this is the first type of query. In this query he will change the character in \(id^{th}\) in position \(pos\) to c, i.e. \(P_{id,pos} = c\)
  2. 2 id c: 2 denotes that this is second type of query. In this query he will append the character c at the end of \(P_{id}\).
  3. 3 id: 3 denotes that this is third type of query. In this query, he will have to find how many names of nice children have \(P_{id}\) as substring.

enter image description here

Input format:
First line contains an integer, N, denoting the number of nice children. Next N lines contains the names of the N nice children. Next line contains an integer, M, denoting the number of naughty children. Next M lines contains the names of the M naughty children. Next line contains an integer, Q \((1 \le Q \le 2 * 10^5)\), denoting the number of queries. Next Q lines contains one of the three types of queries.

Sum of lengths of all the \(S_i \le 2 * 10^5\). Sum of lengths of all the \(P_i \le 2 * 10^5\).

All the indexing will be 1-based.

All \(S_i\) and \(P_i\) are not empty.

Output format:
For each third type query, print an integer, denoting the answer of the third query.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
Tags:
StringHardAlgorithmsOpenApprovedHashing algorithm
Points:50
3 votes
Tags:
HardAlgorithmsString SearchingString AlgorithmsHashingString
Points:50
5 votes
Tags:
String AlgorithmsAlgorithmsHashing algorithmHashing Algorithm