QUE2 - Queue (Pro)
There are N people standing in a Queue. You are given the height of each person and the number of people who are taller and standing ahead of him. You have to find the position of each person.
First line conatins a single integer T, the number of test cases. It is followed by T test cases each of which contains 3 lines. First line of each test case contains a single integer N. Second line contains N integers representing the heights of these N people. Third line also contains N integers denoting the number of taller people standing ahead of him.
Output one line for each test case which contains the heights of the N people in the order in which they are standing.
0 < T <= 20
0 < N <= 10000
Input: 1 5 33 11 22 44 55 0 2 1 1 0 Output: 33 22 11 55 44
Easier Version : Queue (Rookie)
aexpo test case was helpfulLast edit: 2017-09-02 13:21:47
Need some help!
My O(n^2) solution is AC . Don't know how when expected is O(nlogn). :)
jst modified segment tree ....
n (logn)^2 solution works only if BIT is used
my nlogn and n(logn)**2 solution both got acptd with same time - 0.18s .
Enjoyed proving the solution :)
Enjoyed solving it :)