CF2211A.Antimedian Deletion

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Antimedian Deletion

You are given a permutation^{\text{∗}} pp of size nn. You may perform the following operation any number of times:

  • Choose a subarray^{\text{†}} of size 33. Then, delete either the smallest or largest element within it.

For example, for the permutation [2,4,5,3,1][2,4,5,3,1], you may choose the subarray [2,4,5,3,1][\mathbf{2},\mathbf{4},\mathbf{5},3,1]. Since 5=max(2,4,5)5=\operatorname{max}(2,4,5). you can delete 55 to obtain the array [2,4,3,1][2,4,3,1]. You may also choose to delete 22 instead as 2=min(2,4,5)2=\operatorname{min}(2,4,5).

For each ii from 11 to nn, find the minimum length of an obtainable array that contains the number pip_i. Note that this problem is to be solved independently for each ii.

^{\text{∗}}A permutation of length nn is an array consisting of nn distinct integers from 11 to nn in arbitrary order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2] is not a permutation (22 appears twice in the array), and [1,3,4][1,3,4] is also not a permutation (n=3n=3 but there is 44 in the array).

^{\text{†}}An array aa is a subarray of an array bb if aa can be obtained from bb by the deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t5001 \le t \le 500). The description of the test cases follows.

The first line of each test case contains a single integer nn (1n1001 \le n \le 100) — the length of the array.

The second line of each test case contains nn integers p1,p2,,pnp_1, p_2, \ldots, p_n (1pin1 \le p_i \le n). It is guaranteed that each element from 11 to nn appears exactly once.

Output

For each test case, output nn numbers on a new line: the answer for i=1,2,,ni=1,2,\ldots,n.

Note

In the first example, we cannot perform any operations as the size of the array is only 1<31 \lt 3.

In the second example, for i=2i=2, we can choose the subarray [2,1,3][2,1,3], and delete the largest number 33 to obtain the array [2,1][2,1]. It can be shown that 22 is the minimum length of any reachable array that contains a2=1a_2=1.

Samples

2
1
1
3
2 1 3
1
2 2 2

在线编程 IDE

建议全屏模式获得最佳体验