Submit | All submissions | Best solutions | Back to list |
DRUIDEOI - Fata7y Ya Warda! |
Druid (AKA Amr Alaa El-Deen) and little EOIers have finished their training and they are playing "Fatta7y ya warda!". It's a kids game when everyone holds hands with two other kids forming a circle, and they keep saying "Fatta7y ya warda!" (Flourish, flower!) (moving away from each other, while still holding hands, to form a huge circle), then "2affely ya warda!" (Die, flower!) (moving back as close to each other as possible, while still holding hands, to form a tiny circle, i.e. a point). That's it!
Anyway the point is...
While Eagle (AKA Mohamed Ahmed) was watching them playing he was wondering, who's the first person taller than Druid on his left? Similarly, who's the first person taller than Druid on his right? Help Eagle find the answer for each person not just Druid.
Input
The input starts with an integer T (1 ≤ T ≤ 20), the number of test cases.
Each test case contains two lines. The first line contains a single integer N (1 ≤ N ≤ 105), the number of persons playing the game. The second line contains N integers hi (1 ≤ hi ≤ 109) the height of the i-th person. They are numbered 1 to N starting from Druid.
Output
For each test case print N lines, in the i-th line print 2 numbers, the index of the first person taller than the i-th person on his left, and the index of the first person taller than the i-th person on his right. If no one is taller than the i-th person print -1 -1.
Example
Input: 3 5 172 170 168 171 169 3 172 169 172 1 172 Output: -1 -1 1 4 2 4 1 1 4 1 -1 -1 1 3 -1 -1 -1 -1
Note
The third sample:
Added by: | eagle93 |
Date: | 2015-06-20 |
Time limit: | 2s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 JS-MONKEY |
hide comments
|
|||||
2016-01-21 07:08:12 :.Mohib.:
Nice one..!! |
|||||
2015-10-19 22:19:17 Baojun Wang
brute force passed |
|||||
2015-08-10 15:09:00
my solution gives tle. Any hint? |
|||||
2015-07-13 15:21:39 Akash Goel
use scanf printf in c++. |
|||||
2015-07-08 08:17:34 Akhilesh Anandh
nice problem! |
|||||
2015-07-04 13:47:12 Naveen Kumar Shukla
Finally accepted....nice question. Feeling great!! |
|||||
2015-06-30 15:16:02 Marko Puza
I can by no means find out what is wrong with my solution. It works fine with the sample and every possible input I can think of, but I'm still getting WA. :/ |
|||||
2015-06-27 14:57:55 Pranye Mawai
o(n) possible.. nice ques.. |
|||||
2015-06-25 16:06:53 gamer496
Good one |
|||||
2015-06-24 08:14:47 Soma
@anyone : can there be two or more persons with same height? Edit: yes. Last edit: 2015-06-24 08:18:40 |