Nebius Round 2 (Codeforces Round 1088, Div. 1 + Div. 2)
A
Antimedian Deletion
Codeforces
800
原题
←B →
翻译中…

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

翻译中…
  • Choose a subarray$^{\text{†}}$ of size $3$. Then, delete either the smallest or largest 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 $5=\operatorname{max}(2,4,5)$. you can delete $5$ to obtain the array $[2,4,3,1]$. You may also choose to delete $2$ instead as $2=\operatorname{min}(2,4,5)$.

翻译中…

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$.

翻译中…

$^{\text{∗}}$A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array). $^{\text{†}}$An array $a$ is a subarray of an array $b$ if $a$ can be obtained from $b$ 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 $t$ ($1 \le t \le 500$). The description of the test cases follows.

翻译中…

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

翻译中…

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 each element from $1$ to $n$ appears exactly once.

翻译中…

Output

翻译中…

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

翻译中…

Note

翻译中…

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

翻译中…

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

翻译中…

样例

Input #1
2
1
1
3
2 1 3
Output #1
1
2 2 2
InputCopy OutputCopy
题目信息
题号
2211A
时间限制
1 s
内存限制
256 MB
标签
模拟
数学

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