No.1369 Exchange Kadomatsu Sequence: Take
タグ : / 解いたユーザー数 59
作問者 :
夕叢霧香(ゆうむらきりか)
Definition
A sequence of three elements $v = (a_1,a_2,a_3)$ is said by tradition to be a Kadomatsu sequence when $v$ satisfies the following conditions.
- $a_1,a_2,a_3$ are all distinct
- Among the three elements, $a_2$ is the largest or the smallest
Furthermore, a sequence of $n$ elements (where $3\le n$ ) $w = (a_1,...,a_n)$ is called
a Kadomatsu sequence sequence when any three consecutive elements taken from
$w$ form a Kadomatsu sequence.
Problem Statement
You are given a sequence of $N$ elements.
Unfortunately, this sequence is guaranteed not to be a Kadomatsu sequence sequence.
You choose any two elements and swap them exactly once. You cannot choose two elements with the same value. Not swapping at all is also not allowed.
Determine whether the sequence can be made into a Kadomatsu sequence sequence after the above operation.
Input
One input contains $T$ test cases.
The first line gives the number of test cases $T$, and each test case is given in the following two lines each.
$T$
$N_1$
$A_{1,1}\ \ldots\ A_{1,N_1}$
$\ldots$
$N_T$
$A_{T,1}\ \ldots\ A_{T,N_T}$
$1 \le T \le 10^4$
$3 \le N_j \le 5\times 10^4$
$1\le A_{j, i} \le N_j$
$\sum_{j\in 1\ldots T}N_j \le 5\times 10^4$
All values in the input are integers.
In each $j$-th test case, $A_{j,1},\ldots,A_{j,{N_j}}$ is not a Kadomatsu sequence sequence.
Output
For each test case, output Yes if it is possible and No if it is impossible, separated by newlines.
Print a newline at the end.
Sample
Sample 1
Input
4 3 1 2 3 9 1 2 3 4 5 6 7 8 9 8 1 4 2 3 4 2 3 1 9 1 4 2 3 5 8 6 7 1
Output
Yes No No Yes
For 1 2 3,
swapping 1 and 2 gives 2 1 3, which makes the sequence a Kadomatsu sequence sequence.
1 2 3 4 5 6 7 8 9 cannot be made into a Kadomatsu sequence sequence with one swap.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。