Text editor

3.7

3 votes
Hard, AVL tree, Data Structures
Problem

Initially you have the text with lowercase english letters.

You have to proceed q1 queries: replace all occurrences of letter ci in the text with some string stri.

Now you have to find texti, where texti - is the letter on i-th position in the text after all replacements. Positions in the text are numbered from 1.

INPUT

The first line of input contains three integers n,q1,q2 (1n200000,0q1,q2200000) - a length of the text, a number of replacements, a number of queries where the position was asked.

The second line contains text - a string of length n which consists of lowercase english letters.

Then follow q1 lines. The i-th of these lines contains ci and stri. The ci is a lowercase english letter. The stri is nonempty string which consists of lowercase english letters.

Guaranteed that sum of lengths of all stri is not greater than 200000.

Then follow q2 lines. The i-th of these lines contains posi (1posi1016).

OUTPUT

For each posi print textposi or "none" (without quotes) if the length of the text is less than posi.

Time Limit: 2
Memory Limit: 512
Source Limit:
Explanation

Text after first replacement is "ababb".

Text after second replacement is "aabaaabaaba".

Editor Image

?