問題一覧 > 通常問題

No.1369 Exchange Kadomatsu Sequence: Take

レベル : / AI推定難易度 : 1600 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 59
作問者 : mai / テスター : 夕叢霧香(ゆうむらきりか)
お気に入りにしたユーザー ProblemId : 3422 / 自分の提出
問題文最終更新日: 2026-10-20 02:29:20
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 280 (門松コンテスト) (順位表) の他の問題:

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.

  1. $a_1,a_2,a_3$ are all distinct
  2. 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もしくは右上の雲マークをクリックしてアカウントを作成してください。