#Q124. 「一本通 4.2 练习 1」天才的记忆
「一本通 4.2 练习 1」天才的记忆
Description
Original source: Vijos P1512
Once upon a time, there was a person named W and N and B, who possessed a genius-level memory and collected numerous treasures. After his passing, he left behind a puzzle (specifically designed to test memory!) for future generations. Whoever could easily answer this question would inherit his treasures.
The problem is as follows: You are given a long string of numbers (numbered from to , and their sizes may vary!). After you have seen them once, they disappear before your eyes, and then the question arises: You are given queries, each query provides two numbers and , and you must instantly state the maximum number within the interval from to .
One day, a beautiful sister flew by from the sky, saw this problem, and found it very interesting (mainly because it was said that the treasure contained a kind of beauty potion that could make this beautiful sister even more charming). So she tried her best to solve this problem. BUT, she failed every time because the number of digits was simply too large! So she asked you, the genius, to help her solve it. If you help her solve this problem, you will receive many sweet rewards!
Input Format
The first line contains an integer representing the number of digits. The next line contains numbers. The third line contains an integer , indicating the number of times you will be questioned after seeing the string of numbers. The following lines each contain two integers and .
Output Format
Output lines, each containing a number representing the answer to a query.
Sample 1
6
34 1 8 123 3 2
4
1 2
1 5
3 4
2 3
34
123
123
8
Data Range and Hints
For of the data, ;
For of the data, .