시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
5 초 | 256 MB | 19 | 8 | 5 | 55.556% |
Byteasar urgently needs two integer sequences for his research: an increasing one and a decreasing one. However, the only thing he has is a permutation $(p_1, p_2, \ldots, p_n)$ of the numbers in the range $[1, n]$. Can you help him partition this permutation into two such sequences?
Formally, we're looking for two subsequences $p_{r_1}, p_{r_2}, \ldots, p_{r_R}$ and $p_{m_1}, p_{m_2}, \ldots, p_{m_M}$ ($R, M \geq 0$) such that:
The first line of the input contains a single integer $t$ ($1 \leq t \leq 50$) -- the number of testcases in the input file. The following lines describe the consecutive testcases.
A single testcase description consists of two lines. The first of them contains an integer $n$ ($1 \leq n \leq 100\,000$) -- the length of the permutation $(p_i)$. The following line contains $n$ integers $p_1, \ldots, p_n$ ($1 \leq p_i \leq n$ and $p_i \neq p_j$ for all $i \neq j$) -- the permutation itself.
For each testcase (in the order they appear in the input) you should output YES
if the permutation can be partitioned into suitable subsequences or NO
otherwise. If the partitioning is possible, you should output another two lines describing a sample solution. You should follow the format described below: $$R \; p_{r_1} \; p_{r_2} \; \ldots \; p_{r_R}$$ $$M \; p_{m_1} \; p_{m_2} \; \ldots \; p_{m_M}$$ In case there are many solutions, you can output any of them.
3 5 5 1 4 2 3 5 1 2 3 5 4 1 1
YES 2 1 2 3 5 4 3 YES 3 1 2 3 2 5 4 YES 0 1 1