Cannons
Time limit1sMemory limit128 MB
For each query, report the minimum and maximum value in the given subarray of cannon strengths.
- Level
Medium4 of 10
- Topics
- Segment tree, Array
- Solved
- No attempts yet
Problem
A certain kingdom is preparing for war. Its army consists mainly of cannons, and the tactics for using them are very simple. The kingdom owns cannons. During a battle they are placed one after another along the front line. The cannons are numbered from to , from left to right. Each cannon has an associated integer denoting its combat strength.
The Royal Combat Analysis Center (CAB) is responsible for battle tactics. While preparing for war, CAB considers various battle scenarios. A scenario assumes that the front is attacked along the segment from cannon to cannon . To choose the most effective tactic, CAB needs to know the minimum and maximum combat strength among the cannons on that segment. Help CAB solve this quickly.
Input
The first line contains a natural number (), the number of tests. The descriptions of the tests follow one after another.
The first line of each test contains an integer (), the number of cannons. The second line contains integers (), the combat strengths of the cannons. The next line contains an integer (), the number of scenarios CAB considers. Each of the following lines contains one scenario, given as two integers and ().
Output
For each scenario, print the minimum and the maximum combat strength among the cannons on the segment from cannon to cannon , separated by a single space on one line.