問題一覧 > 通常問題

No.1707 Simple Range Reverse Problem

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 162
作問者 : chineristAC / テスター : 👑 hitonanode 👑 箱星
お気に入りにしたユーザー ProblemId : 6832 / 自分の提出
問題文最終更新日: 2021-10-06 17:23:32
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 318 (順位表) の他の問題:

Problem Statement

There is a sequence $X=(X_1,\ X_2,\ \dots,\ X_{2N})$ of length $2N$. Initially, $X$ satisfies $X_i=i,\ X_{i+N}=i$ for every $1 \le i \le N$.

Given a sequence $A=(A_1,\ A_2,\ \dots,\ A_{2N})$ of length $2N$, determine whether $X$ can be made equal to $A$ by performing the following operation on $X$ $0$ or more times.

Operation
  • Choose $l,\ r\ (1\le l < r \le 2N)$ such that $X_l=X_r$. Then, replace $X_l,\ X_{l+1},\ \dots,\ X_{r-1},\ X_{r}$ with $X_{r},\ X_{r-1},\ \dots,\ X_{l+1},\ X_{l}$, respectively.

Solve $T$ test cases.

Input

First, the number of test cases $T$ is given on line $1$ of the input.

$T$

Then, $T$ test cases follow, each given in the following format.

$N$
$A_1$ $A_2$ $\dots$ $A_{2N}$
  • $1 \le T \le 100$
  • $1 \le N \le 1000$
  • $1 \le A_i \le N$
  • The sum of $N$ over all test cases is at most $1000$.
  • All input values are integers.

Output

For each test case, print Yes if $X$ can be made equal to $A$, and No otherwise, on $1$ line.

Print a newline at the end.

Sample

Sample 1
Input
4
3
1 2 3 2 1 3
3
1 2 3 1 2 3
4
3 2 4 3 4 2 1 1
5
5 4 3 2 1 1 2 3 4 5
Output
Yes
Yes
No
No

For test case $1$, starting from the state $X=(1,\ 2,\ 3,\ 1,\ 2,\ 3)$, $X$ can be made equal to $A$ by performing the operation $1$ time with $l=3,\ r=6$.

For test case $2$, in the state $X=(1,\ 2,\ 3,\ 1,\ 2,\ 3)$, $X$ is already equal to $A$.

For test cases $3,\ 4$, $X$ cannot be made equal to $A$ no matter how the operations are performed.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。