Christmas queries

0

0 votes
Algorithms, Hard, Approved, String, Hashing algorithm
Problem

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 idth in position pos to c, i.e. Pid,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 Pid.
  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 Pid 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 (1Q2105), denoting the number of queries. Next Q lines contains one of the three types of queries.

Sum of lengths of all the Si2105. Sum of lengths of all the Pi2105.

All the indexing will be 1-based.

All Si and Pi are not empty.

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

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation
  1. First a is substring of aa, ab, aac. So answer is 3.
  2. Second a is now ab.
  3. ab is substring of ab. So answer is 1.
  4. ab is aa now.
  5. aa is substring of aa, aac. So answer is 2.
Editor Image

?