#P7475. 「C.E.L.U-02」简易输入法

    ID: 5577 远端评测题 2000ms 384MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>平衡树O2优化树套树字典树,Trie 树

「C.E.L.U-02」简易输入法

Description

This simple input method originally has a dictionary U\text{U}. When the user types, the input method reads a string ss and an integer xx from the user. For this string, there are several cases:

Let the number of words siUs_i \in \text{U} such that ss is a prefix of sis_i be aa.

  • When axa \ge x, output the xx-th sis_i after sorting by output count in descending order as the first key and lexicographical order as the second key, and then increase its output count by 11.
  • When x>a>0x > a > 0, output the last sis_i after sorting by output count in descending order as the first key and lexicographical order as the second key, and then increase its output count by 11.
  • When a=0a = 0, output 404Error.

Input Format

Line 11 contains an integer nn, representing that there are originally nn words in U\text{U}. The initial output count of every originally existing word is 00.

Lines 22 to n+1n+1 each contain a string strstr, representing a word that originally exists in the dictionary.

Line n+2n+2 contains an integer mm, representing that the user performs mm operations.

Lines n+3n+3 to n+m+2n+m+2 each contain a string ss and an integer xx, whose meanings are described above.

Output Format

For each of the user’s 11 operation, output a string.

3
fan
fantasy
father
6
fat 1
fa 1
fan 1
fan 1
fa 1
fant 1
father
father
fan
fan
fan
fantasy
5
uva
usaco
usa
usssu
konjac
11
u 2
u 2
kkk 1
uv 2
us 3
u 4
u 1
u 2
k 1
u 3
usa 1
usaco
usa
404Error
uva
usssu
uva
uva
usa
konjac
usaco
usa

Hint

Sample Explanation

Sample Explanation 1

There is only 11 word with prefix fat, so output father, and increase its output count by 11.
For prefix fa, the word with the highest output count is father, so output it, and increase its output count by 11.
For prefix fan, all output counts are 00, but fan is the smallest in lexicographical order, so output it, and increase its output count by 11.
For prefix fan, the word with the highest output count is fan, so output fan, and increase its output count by 11.
For prefix fa, the word with the highest output count is fan, so output it, and increase its output count by 11.
There is only one word with prefix fant, which is fantasy, so output it, and increase its output count by 11.

Constraints

Test ID nn mm xx str\sum str
121\sim 2 100\le100 =1=1 103\le10^3
343\sim 4 \diagdown 10310^3
585\sim 8 5×104\le5\times10^4 105\le10^5 =1=1 5×105\le5\times10^5
9149\sim 14 104\le10^4 \diagdown 105\le10^5
152015\sim 20 5×104\le5\times10^4 5×105\le5\times10^5

For 100%100\% of the testdata, s,str10,1x104|s|,|str|\le10,1\leq x\le10^4, and all letters are lowercase letters.

Translated by ChatGPT 5