Mark has an array, \(A\) of \(N\) elements. He performs \(Q\) queries in it. In each query, he chooses an index \(I\)(\(0\)- based) and does the following:
for j = I + 1 to N:
if A[j] < A[I]:
A[j] = 0
You need to print what array \(A\) looks like after processing all the \(Q\) queries.
Note : The queries are not independent of each other i.e. you need to use the changed array \(A\), for each query.
Constraints
\(1 \le T \le 10\)
\(1 \le N \le 10^5\)
\(1 \le A_i \le 10^9\)
\(1 \le Q \le 10^5\)
Input
The first line of input has an integer \(T\), denoting the number of test cases. Each test case will consist of \(3\) lines, the first line contains \(2\) space seperated integers, \(N\) and \(Q\), denoting the number of elements in the array and number of queries.
\(2^{nd}\) line will have \(N\) space separated integers denoting the elements in the initial array \(A\) .
\(3^{rd}\) line will have \(Q\) space separated integers denoting the chosen index in the each query.
Output
For each test case, output in a seperate line, \(N\) space separated integers denoting the final array \(A\) .
2 5 2 4 3 4 3 2 3 2 3 1 3 2 1 2
4 3 4 0 0 3 2 1
Hint: Use an advanced sorting algorithm.
In the first test case :
Array after \(1^{st}\) query : \(\{4,3,4,3,0\}\)
Array after \(2^{nd}\) query : \(\{4,3,4,0,0\}\)
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor