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.
Input
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
Output one line for each test case which contains the heights of the N people in the order in which they are standing.
Constraints
0 < T <= 20
0 < N <= 10000
Example
Input: 1 5 33 11 22 44 55 0 2 1 1 0 Output: 33 22 11 55 44
Easier Version : Queue (Rookie)
hide comments
sandeep_123:
20171215 14:05:27
Great problem !! did with vector erase, without segment tree :D complexity  O(N*log(N)) 

Piyush Agarwal:
20170902 13:21:26
aexpo test case was helpful Last edit: 20170902 13:21:47 

aexpo:
20170725 16:33:58
Need some help!


sonu:
20170622 09:35:30
My O(n^2) solution is AC . Don't know how when expected is O(nlogn). :)


sultania23:
20170323 20:14:21
jst modified segment tree .... 

AAKASH TYAGI:
20160630 00:09:20
n (logn)^2 solution works only if BIT is used


enigmus:
20160229 18:24:34
Trees!!! 

Abhinandan Agarwal:
20151022 22:26:15
my nlogn and n(logn)**2 solution both got acptd with same time  0.18s . 

Rang:
20150608 12:06:04
Enjoyed proving the solution :) 
Added by:  @ce 
Date:  20130916 
Time limit:  0.100s0.25s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: ASM64 
Resource:  Directi Interview 