Antimedian Deletion
题面
You are given a permutation of size . You may perform the following operation any number of times:
- Choose a subarray of size . Then, delete either the smallest or largest element within it.
For example, for the permutation , you may choose the subarray . Since . you can delete to obtain the array . You may also choose to delete instead as .
For each from to , find the minimum length of an obtainable array that contains the number . Note that this problem is to be solved independently for each .
A permutation of length is an array consisting of distinct integers from to in arbitrary order. For example, is a permutation, but is not a permutation ( appears twice in the array), and is also not a permutation ( but there is in the array).
An array is a subarray of an array if can be obtained from 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 (). The description of the test cases follows.
The first line of each test case contains a single integer () — the length of the array.
The second line of each test case contains integers (). It is guaranteed that each element from to appears exactly once.
Output
For each test case, output numbers on a new line: the answer for .
思路
看清题目要求:
在一个长度为 的排列中反复进行下面的操作:
- 选一个长度为3的连续子数组,然后删掉这个数组里的最大值或者最小值
而很明显,由于这个操作给定的目标长度必须是3,而每次长度必定会 ,导致最终长度必定不会小于2
所以,结论很容易出来:
代码
#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]; } } }
}