아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Permutation

시간 제한5초메모리 제한256 MB

요약
1부터 n까지의 순열을 증가 부분수열과 감소 부분수열로 나눌 수 있는지 판정하고, 가능하면 그중 하나를 출력한다.
난이도

보통10점 중 7점

유형
그리디, 구현, 배열, 정렬
정답자
아직 제출이 없습니다

문제

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,…,p_n)(p\_1, p\_2, \ldots, p\_n) of the numbers in the range \[1,n]\[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,…,p_r_Rp\_{r\_1}, p\_{r\_2}, \ldots, p\_{r\_R} and p_m_1,p_m_2,…,p_m_Mp\_{m\_1}, p\_{m\_2}, \ldots, p\_{m\_M} (R,M≥0R, M \geq 0) such that:

  • 1≤r_1<…<r_R≤n1 \leq r\_1 < \ldots < r\_R \leq n and p_r_1<…\<p_r_Rp\_{r\_1}<\ldots\<p\_{r\_R},
  • 1≤m_1<…<m_M≤n1 \leq m\_1 < \ldots < m\_M \leq n and p_m_1>…>p_m_Mp\_{m\_1}>\ldots>p\_{m\_M},
  • r_i≠m_jr\_i \neq m\_j for all i,ji,j (1≤i≤R1\leq i\leq R, 1≤j≤M1\leq j\leq M),
  • R+M=nR+M=n.

입력

The first line of the input contains a single integer tt (1≤t≤501 \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 nn (1≤n≤100,0001 \leq n \leq 100\\,000) -- the length of the permutation (p_i)(p\_i). The following line contains nn integers p_1,…,p_np\_1, \ldots, p\_n (1≤p_i≤n1 \leq p\_i \leq n and p_i≠p_jp\_i \neq p\_j for all i≠ji \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;…;p_r_RR \\; p\_{r\_1} \\; p\_{r\_2} \\; \ldots \\; p\_{r\_R} M;p_m_1;p_m_2;…;p_m_MM \\; p\_{m\_1} \\; p\_{m\_2} \\; \ldots \\; p\_{m\_M} In case there are many solutions, you can output any of them.

예제1

  1. 예제 1

    입력
    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