luogu#P10564. [ICPC2024 Xi'an I] Rubbish Sorting

[ICPC2024 Xi'an I] Rubbish Sorting

题目描述

Bob has many pieces of rubbish. One day, he wants to sort them.

For every piece of rubbish, its type is expressed as a positive integer.

He has qq operations. For each operation, it is one of the following two operations.

  • 1 s x He tells you that the piece of rubbish named ss has a type of xx.
  • 2 s He wants to ask you the type of rubbish ss.

But his memories are not always accurate.

For each operation 22, ss may not have appeared in the previous operation 11s.

We define the similarity of two strings s1s_1 and s2s_2 as i=1min{s1,s2}[s1,i=s2,i]\sum_{i=1}^{\min\{|s_1|,|s_2|\}} [s_{1,i}=s_{2,i}].

Here all the strings' indexes start at 11.

For a string ss, its type is the type of string which has the maximum similarity to ss among all the strings that have appeared in the previous operations 11s. Note that if there are multiple strings that all have the maximum similarity to ss, the type of ss is the minimum type of these strings' type.

Now, he wants you to solve this problem.

输入格式

The first line contains an integer q(1q3×105)q(1\le q\le 3\times 10^5), which is the number of operations.

Next qq lines contain operations, one per line. They correspond to the description given in the statement.

It is guaranteed that for every operation 22 there is at least one operation 11 before it.

But some pieces of rubbish will have more than one type, you can consider it as the minimum type you have read.

The rubbish's names only consist of lowercase Latin letters.

1s5,1x1091 \le |s| \le 5, 1 \le x \le 10^9

输出格式

For every operation 22, you should print an integer in a single line that is the rubbish ss's type.

4
1 aaa 1
2 aa
1 ab 2
2 bb
1
2