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
vietnamican:
20190327 04:42:43
This problem just need O(n) 

agrawal117:
20190320 11:20:14
again and again TLE coming why?? pls help !! 

anirudnits:
20190102 19:22:18
@vivek_shah98 Thanks :) 

vivek_shah98:
20181007 08:21:06
I solved this problem in O(nlog(n)) using Policy based data structures on indexes.. 

rajcoolaryan:
20180622 14:20:25
if you know vector .. u are done with this ques .. 

aman_sachin200:
20180605 17:20:56
Nice One!!!BIT+Binary Search :)!!!Solve the rookie problem first.. 

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). :)

Added by:  Shikhar 
Date:  20130916 
Time limit:  0.100s0.25s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: ASM64 
Resource:  Directi Interview 