No.1707 Simple Range Reverse Problem
タグ : / 解いたユーザー数 162
作問者 :
hitonanode
👑 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もしくは右上の雲マークをクリックしてアカウントを作成してください。