#C815. Spell Summit
Spell Summit
Spell Summit
In a mystical kingdom, elder creatures possess unique enchantment phrases. During the Spell Summit, Merlin displays certain magical phrases. Each displayed phrase may match as a prefix for one or more elder enchantment phrases. There are two types of sessions at this summit:
-
Session Type 1: Merlin displays a phrase. For each such phrase, for every elder, if the displayed phrase starts with the elder's enchantment phrase, a counter for that elder is increased.
-
Session Type 2: A query is made for a specific elder (by index) asking how many times a displayed phrase has had a prefix matching the elder's enchantment phrase so far.
Given the number of elders and their enchantment phrases, followed by a series of sessions, your task is to print the answer for each query (Session Type 2).
Note: A string s1 is said to be a prefix of string s2 if ( s2[0..|s1|-1] = s1 ) (in (\LaTeX) format).
inputFormat
The input is given via standard input and has the following format:
- The first line contains an integer ( n ) that denotes the number of elder creatures.
- The next ( n ) lines each contain a non-empty string representing an elder's enchantment phrase.
- The following line contains an integer ( q ) indicating the number of sessions.
- Each of the next ( q ) lines describes a session. A session line starts with an integer ( t ):
- If ( t = 1 ), it is followed by a space and a string ( P ) representing a phrase displayed by Merlin.
- If ( t = 2 ), it is followed by a space and an integer ( E ) (1-indexed) representing the elder creature for which the query is made.
outputFormat
For every session of type 2, output the current count (on its own line) of displayed phrases that have the corresponding elder's enchantment phrase as a prefix.## sample
3
spell
magic
wizard
4
1 spellbound
1 magicians
2 2
2 1
1
1
</p>