482 字
2 分钟
Antimedian-Deletion

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.

思路#

看清题目要求:

在一个长度为 nn 的排列中反复进行下面的操作:

  • 选一个长度为3的连续子数组,然后删掉这个数组里的最大值或者最小值

而很明显,由于这个操作给定的目标长度必须是3,而每次长度必定会 1-1,导致最终长度必定不会小于2

所以,结论很容易出来:

  • n=1,ans=1n=1, ans=1
  • n2,ans=2,2,2,2n \leq 2, ans=2, 2, 2, 2 \dots

代码#

#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t --) {
int n;
cin >> n;
vector<int> p(n);
for (int i = 0; i < n; i ++) cin >> p[i];
if (n == 1) cout << 1 << endl;
else {
for (int i = 0; i < n; i ++) {
cout << 2 << " \n"[i == n - 1];
}
}
}
}
Antimedian-Deletion
https://github.com/posts/antimedian-deletion/
作者
FZSGBall
发布于
2026-04-18
许可协议
CC BY-NC-SA 4.0