You are given an array of A of N elements. You have performed Q queries in it. In each query, you can select an index I (0 - based) and perform the following operation:
for j = I + 1 to N
if A[j] < A[I]
A[j] = 0You are required to print the version of array A after all queries Q.
Constraints:
1 <= T <= 10 (test cases)
1 <= N <= 10^5
1 <= A[i] <= 10^9
1 <= Q <= 10^5
Examples:
Input1:
1 (no of test cases)
5 2 (N & Q)
4 3 4 3 2 (array A)
3 2 (the queries)
Output1:
4 3 4 0 0
Explanation:
After the first query I = 3: {4, 3, 4, 3, 0}
After the second query I = 2: {4, 3, 4, 0, 0}
Input2:
1
7 5
4 4 3 3 100 100 7 2
7 5 2 0 0
Output2:
4 4 0 0 100 100 0 0
Taken from here.