#P13786. [eJOI 2022] LCS of Permutations

[eJOI 2022] LCS of Permutations

题目描述

For two sequences xx and yy, we define LCS(x,y)LCS(x, y) as the length of their longest common subsequence.

You are given 4 integers n,a,b,cn, a, b, c. Determine if there exist 3 permutations p,q,rp, q, r of integers from 1 to nn, such that:

  • LCS(p,q)=aLCS(p, q) = a
  • LCS(p,r)=bLCS(p, r) = b
  • LCS(q,r)=cLCS(q, r) = c

If such permutations exist, find any such triple of permutations.

A permutation pp of integers from 1 to nn is a sequence of length nn such that all elements are distinct integers in the range [1,n][1, n]. For example, (2,4,3,5,1)(2, 4, 3, 5, 1) is a permutation of integers from 1 to 5 while (1,2,1,3,5)(1, 2, 1, 3, 5) and (1,2,3,4,6)(1, 2, 3, 4, 6) are not.

A sequence cc is a subsequence of a sequence dd if cc can be obtained from dd by deletion of several (possibly, zero or all) elements. For example, (1,3,5)(1, 3, 5) is a subsequence of (1,2,3,4,5)(1, 2, 3, 4, 5) while (3,1)(3, 1) is not.

The longest common subsequence of the sequences xx and yy is the longest sequence zz which is a subsequence of both xx and yy. For example, the longest common subsequence of the sequences x=(1,3,2,4,5)x = (1, 3, 2, 4, 5) and y=(5,2,3,4,1)y = (5, 2, 3, 4, 1) is z=(2,4)z = (2, 4) since it is a subsequence of both sequences and is the longest among such subsequences. LCS(x,y)LCS(x, y) is the length of the longest common subsequence, which is 2 in the example above.

输入格式

The first line of the input contains a single integer tt (1t1051 \leq t \leq 10^5) - the number of test cases. The description of the test cases follows.

The only line of each test case contains 5 integers n,a,b,c,outputn, a, b, c, output (1abcn21051 \leq a \leq b \leq c \leq n \leq 2 \cdot 10^5, 0output10 \leq output \leq 1).

If output=0output = 0, just determine if such permutations exist. If output=1output = 1, you also have to find such a triple of permutations if it exists.

It's guaranteed that the sum of nn over all test cases doesn't exceed 21052 \cdot 10^5.

输出格式

For each test case, in the first line, output "YES", if such permutations p,q,rp, q, r exist, and "NO" otherwise. If output=1output = 1, and such permutations exist, output three more lines:

In the first line output nn integers p1,p2,,pnp_1, p_2, \ldots, p_n - the elements of the permutation pp.

In the second line output nn integers q1,q2,,qnq_1, q_2, \ldots, q_n - the elements of the permutation qq.

In the third line output nn integers r1,r2,,rnr_1, r_2, \ldots, r_n - the elements of the permutation rr.

If there are multiple triples, output any of them.

You can output each letter in any case (for example, "YES", "Yes", "yes", "yEs", "yEs" will be recognized as a positive answer).

8
1 1 1 1 1
4 2 3 4 1
6 4 5 5 1
7 1 2 3 1
1 1 1 1 0
4 2 3 4 0
6 4 5 5 0
7 1 2 3 0
YES
1
1
1
NO
YES
1 3 5 2 6 4
3 1 5 2 4 6
1 3 5 2 4 6
NO
YES
NO
YES
NO

提示

Note

In the first test case, LCS((1),(1))LCS((1), (1)) is 1.

In the second test case, it can be shown that no such permutations exist.

In the third test case, one of the examples is p=(1,3,5,2,6,4)p = (1, 3, 5, 2, 6, 4), q=(3,1,5,2,4,6)q = (3, 1, 5, 2, 4, 6), r=(1,3,5,2,4,6)r = (1, 3, 5, 2, 4, 6). It's easy to see that:

  • LCS(p,q)=4LCS(p, q) = 4 (one of the longest common subsequences is (1,5,2,6)(1, 5, 2, 6))
  • LCS(p,r)=5LCS(p, r) = 5 (one of the longest common subsequences is (1,3,5,2,4)(1, 3, 5, 2, 4))
  • LCS(q,r)=5LCS(q, r) = 5 (one of the longest common subsequences is (3,5,2,4,6)(3, 5, 2, 4, 6))

In the fourth test case, it can be shown that no such permutations exist.

Scoring

  1. (3 points): a=b=1,c=n,output=1a = b = 1, c = n, output = 1
  2. (8 points): n6,output=1n \leq 6, output = 1
  3. (10 points): c=n,output=1c = n, output = 1
  4. (17 points): a=1,output=1a = 1, output = 1
  5. (22 points): output=0output = 0
  6. (40 points): output=1output = 1