Length of a valley
92% Success7445 Attempts30 Points2s Time Limit256MB Memory1024 KB Max Code

You are given an integer array \(A\) consisting of \(N\) elements. For each element, you are required to find the length of the valley that is defined as:

Let \(i\) be the current index and \(l\) and \(r\) be the leftmost and rightmost index satisfying this property \(a[l]>a[l+1].....>a[i-1]>a[i], then \((r-l+1)\) is the length of the valley. Also, assume that if \(A\) is \([7,2,1,5,7,9]\), then the answer is \([1,2,6,3,2,1]\).

Explanation

  • A1 (7): The answer is 1 because there is no element to the left and in right 2 is smaller than 7.
  • A2 (2): A1>A2, therefore, the answer is 2
  • A3 (1): A1>A2>A3456, therefore, the answer is 6
  • A4 (5): A456, therefore, the answer is 3
  • A5 (7): A56, therefore, the answer is 2
  • A6 (9): 7 is smaller than 9 and there is no element to the right, therefore, the answer is 1

Input format

  • The first line contains an integer \(T\) denoting the number of test cases.
  • The first line of each test case contains an integer \(N\) denoting the number of elements in array \(A\).
  • The second line of each test case contains \(N\) space-separated integers of array \(A\).

Output format

Print \(T\) lines. For each test case, print \(N\) space-separated integers denoting the length of the valley for each index.

Constraints

\(1 \leq T \leq 20000\)

\(1 \leq N \leq 500000\)

\(1 \leq A_i \leq 10^9\)

Sum of \(N\) over all test cases does not exceed 1000000

Examples
Input
1
6
7 2 1 5 7 9
Output
1 2 6 3 2 1
Explanation

-

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

Loading Editor...
Results