#P2412. 查单词

查单词

Description

HansBug found a word list in an English book, containing NN words (each word consists of uppercase and lowercase letters). He wants to find the lexicographically largest word within a contiguous segment.

Input Format

The first line contains two positive integers NN and MM, representing the number of words and the number of queries.

The next NN lines each contain a string consisting only of uppercase and lowercase letters, with length at most 1515, representing a word. Words are case-insensitive.

The next MM lines each contain two integers xx and yy, asking for the lexicographically largest word from the xx-th to the yy-th word. If two words are the same in lexicographical order when ignoring case, output the one that appears later.

Output Format

Output MM lines, each containing a string, corresponding to the results of the MM queries in order.

5 5
absi
hansbug
lzn
kkk
yyy
1 5
1 1
1 2
2 3
4 4
yyy
absi
hansbug
lzn
kkk

Hint

Sample Explanation

First operation: find the lexicographically largest in {absi,hansbug,lzn,kkk,yyy}\tt\left\{absi,hansbug,lzn,kkk,yyy\right\}, which is yyy\tt yyy.

Second operation: find the lexicographically largest in {absi}\tt\left\{absi\right\}, which is absi\tt absi.

Third operation: find the lexicographically largest in {absi,hansbug}\tt\left\{absi,hansbug\right\}, which is hansbug\tt hansbug.

Fourth operation: find the lexicographically largest in {hansbug,lzn}\tt\left\{hansbug,lzn\right\}, which is lzn\tt lzn.

Fifth operation: find the lexicographically largest in {kkk}\tt\left\{kkk\right\}, which is kkk\tt kkk.

Constraints

Translated by ChatGPT 5