luogu#P4728. [HNOI2009] 双递增序列

[HNOI2009] 双递增序列

Problem Description

Consider a sequence a1,a2,,ana_1, a_2, \dots, a_n of even length nn. We call this sequence good if and only if there exists a partition of a1,a2,,ana_1, a_2, \dots, a_n into two sets U={ai1,ai2,,ain/2}U=\{ a_{i_1}, a_{i_2}, \dots, a_{i_{n/2}} \} and $V=\{ a_{j_1}, a_{j_2}, \dots, a_{j_{n/2}} \}=\{ a_1, a_2, \dots, a_n \}-U$, such that i1<i2<<in/2i_1<i_2< \dots <i_{n/2}, ai1<ai2<<ain/2a_{i_1}<a_{i_2}< \dots <a_{i_{n/2}}, j1<j2<<jn/2j_1<j_2< \dots <j_{n/2}, and aj1<aj2<<ajn/2a_{j_1}<a_{j_2}< \dots <a_{j_{n/2}}.

For example, the sequence 3,1,4,5,8,73, 1, 4, 5, 8, 7 is a good sequence, because it can be split into U={3,4,8}U=\{3, 4, 8\} and V={1,5,7}V=\{1, 5, 7\}. However, the sequence 3,2,1,6,5,43, 2, 1, 6, 5, 4 is not a good sequence.

Now, for several given sequences, please determine whether each of them is a good sequence.

Input Format

The first line contains only one integer mm, indicating that you need to judge mm sequences.
The next mm lines give these sequences. Each sequence is given on one line: the first number is an even integer nn, indicating the length of the sequence, and the following nn integers are the elements of the sequence a1,a2,,ana_1, a_2, \dots, a_n. Numbers on the same line are separated by a single space.

Output Format

Output mm lines. If the ii-th sequence is a good sequence, output Yes! on the ii-th line; otherwise, output No!.

2
6 3 1 4 5 8 7
6 3 2 1 6 5 4
Yes!
No!

Hint

For 10%10\% of the testdata, n100n \le 100.
For 40%40\% of the testdata, n300n \le 300.
For 100%100\% of the testdata, 1n20001 \le n \leq 2000, 1m251 \le m \leq 25, 0ai1060 \le a_i \le 10^6.

Translated by ChatGPT 5