#P16394. [ECUSTPC 2026 Spring] 回响形态

    ID: 18408 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>数学Special Judge构造2026高校校赛

[ECUSTPC 2026 Spring] 回响形态

Background

:::epigraph Did you manage to construct the sequence?

You managed to construct the sequence. :::

Problem Description

The Construction Kingdom is still chasing Little T……

For a sequence of length nn, define its prefix max⁡\max sequence xx as xi=max⁡{aj:1≤j≤i}x_i = \max\{a_j : 1 \le j \le i\}, and its prefix min⁡\min sequence yy as yi=min⁡{aj:1≤j≤i}y_i = \min\{a_j : 1 \le j \le i\}.

Given nn and kk, please construct two sequences aa and bb of length nn that satisfy the following conditions. If no such two sequences exist, report that there is no solution:

  • aa and bb are permutations of 11 to nn.
  • aa and bb differ in at least one position, i.e., there exists ii such that ai≠bia_i \ne b_i.
  • For either sequence among aa and bb, let its prefix max⁡\max sequence be xx and prefix min⁡\min sequence be yy. It must satisfy:
∑i=1n(xi−yi)=k.\sum_{i=1}^{n}(x_i - y_i) = k.

Input Format

The first line contains an integer T (1≤T≤105)T \ (1 \le T \le 10^5), denoting the number of testdata.

Each testdata contains one line with two integers nn and k (2≤n≤105,0≤k≤1010)k \ (2 \le n \le 10^5, 0 \le k \le 10^{10}), denoting the length of the sequence and the difference between the prefix max⁡\max and prefix min⁡\min.

It is guaranteed that ∑n≤3×105\sum n \le 3 \times 10^5 over all testdata.

Output Format

For each testdata, if there exist two sequences that satisfy the conditions, output two lines.

The first line outputs nn integers a1,a2,…,ana_1, a_2, \dots, a_n, representing the first sequence aa you constructed.

The next line outputs nn integers b1,b2,…,bnb_1, b_2, \dots, b_n, representing the second sequence bb.

If no such two sequences exist, output one line containing a single integer −1-1.

If there are multiple valid answers, you may output any one of them.

3
2 1
2 0
5 12
1 2
2 1
-1
1 3 4 2 5
1 2 4 5 3

Hint

Sample 1 Explanation

For the 3rd testdata, we verify whether the second sequence, i.e. sequence bb, satisfies the conditions:

  • {1,2,4,5,3}\{1, 2, 4, 5, 3\} is a permutation of 11 to 55, because each integer appears exactly once.
  • The second element is a2=3a_2 = 3, b2=2b_2 = 2, and a2≠b2a_2 \ne b_2.
  • Its prefix max⁡\max sequence is x={1,2,4,5,5}x = \{1, 2, 4, 5, 5\}, and its prefix min⁡\min sequence is y={1,1,1,1,1}y = \{1, 1, 1, 1, 1\}. Thus,
$$\sum_{i=1}^{n}(x_i - y_i) = (1 - 1) + (2 - 1) + (4 - 1) + (5 - 1) + (5 - 1) = 0 + 1 + 3 + 4 + 4 = 12 = k.$$

Hint

A permutation of 11 to nn is a sequence of length nn in which each integer from 11 to nn appears exactly once.

Translated by ChatGPT 5