Nebius Round 2 (Codeforces Round 1088, Div. 1 + Div. 2)
H
Median Deletion
Codeforces
3500
原题
← G→
翻译中…

You are given a permutation $p$ of size $n$. You may perform the following operation any number of times:

翻译中…
  • Choose a subarray of size $3$. Then, delete the second smallest element within it.
翻译中…

For example, for the permutation $[2,4,5,3,1]$, you may choose the subarray $[\mathbf{2},\mathbf{4},\mathbf{5},3,1]$. Since $4$ is the second smallest element out of $[2,4,5]$, you can delete $4$ to obtain the array $[2,5,3,1]$.

翻译中…

For each $i$ from $1$ to $n$, find the minimum length of an obtainable array that contains the number $p_i$. Note that this problem is to be solved independently for each $i$.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the length of the permutation.

翻译中…

The second line of each test case contains $n$ integers $p_1, p_2, \ldots, p_n$ ($1 \le p_i \le n$).

翻译中…

It is guaranteed that the given $p$ is a permutation.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

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

翻译中…

Note

翻译中…

In the second example, for $i=1$, we can get an array of size $2$ as follows:

翻译中…
  • Choose the subarray $[4,2,1]$. Delete the median $2$. The array is now $[4,1,3]$.
  • Choose the subarray $[4,1,3]$. Delete the median $3$. The array is now $[4,1]$.
翻译中…

It can be shown that $2$ is the minimum length of any reachable array that contains $a_1=4$.

翻译中…

For $i=4$, the answer is $3$, with the minimum length reachable array containing $a_4=3$ being $[4,1,3]$.

翻译中…

样例

Input #1
6
1
1
4
4 2 1 3
5
4 1 3 5 2
6
1 4 3 5 2 6
6
1 5 3 4 2 6
8
4 3 7 5 1 6 8 2
Output #1
1
2 4 2 3
3 2 5 2 3
2 3 3 3 3 2
2 3 5 5 3 2
3 3 3 5 2 5 2 3
InputCopy OutputCopy
题目信息
题号
2211H
时间限制
2 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。