#P16462. [UOI 2026] Divisors

    ID: 16447 Type: RemoteJudge 700ms 512MiB Tried: 0 Accepted: 0 Difficulty: 7 Uploaded By: Tags>Special Judge2026UOI(乌克兰)

[UOI 2026] Divisors

题目描述

You are given 2n2n integers b1,b2,,b2nb_1, b_2, \dots, b_{2n} and an integer xx. For all ii, it holds that 1bix1 \le b_i \le x.

In one operation, you may choose any index ii (1i2n1 \le i \le 2n) and increase the number bib_i by 11.

You need to perform no more than x2\left\lfloor \frac{x}{2} \right\rfloor operations and split all numbers into nn pairs so that in each pair, after performing the operations, one number is divisible by the other.

In other words, you need to find non-negative integers d1,d2,,d2nd_1, d_2, \dots, d_{2n} and a partition of the indices 1,2,,2n1, 2, \dots, 2n into nn pairs such that:

  • $\sum\limits_{i=1}^{2n} d_i \le \left\lfloor \frac{x}{2} \right\rfloor$, that is, the sum of all did_i does not exceed x2\frac{x}{2} rounded down;
  • if ci=bi+dic_i = b_i + d_i, then for every pair of indices (u,v)(u, v), either cucvc_u \mid c_v or cvcuc_v \mid c_u, that is, either cuc_u divides cvc_v or cvc_v divides cuc_u.

It is guaranteed that for the given constraints, an answer always exists.

y\left\lfloor y \right\rfloor denotes the greatest integer not exceeding yy. For example, 7/2=3\left\lfloor 7/2 \right\rfloor = 3.

输入格式

The first line contains one integer tt (1t104)(1 \le t \le 10^4) --- the number of test cases.

Each test case consists of two lines.

The first line of a test case contains two integers nn and xx (1n1051 \le n \le 10^5, 1x1091 \le x \le 10^9).

The second line contains 2n2n integers b1,b2,,b2nb_1, b_2, \dots, b_{2n} (1bix1 \le b_i \le x).

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

输出格式

For each test case, output the answer in the following format.

First, output nn lines. In the jj-th of them, output two integers uju_j and vjv_j --- the indices of the numbers that form the jj-th pair.

Each index from 11 to 2n2n must appear in exactly one pair.

After that, output one line with 2n2n integers d1,d2,,d2nd_1, d_2, \dots, d_{2n}, where did_i is the number of operations performed on the number bib_i.

The following must hold: di0 d_i \ge 0 for all 1i2n1 \le i \le 2n, and also $\sum\limits_{i=1}^{2n} d_i \le \left\lfloor \frac{x}{2} \right\rfloor.$

Let ci=bi+dic_i = b_i + d_i. For each printed pair (uj,vj)(u_j, v_j), it must hold that: $c_{u_j} \mid c_{v_j} \quad \text{or} \quad c_{v_j} \mid c_{u_j}.$

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

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

提示

In the first example, we can split the numbers into pairs (3,3)(3, 3), (1,8)(1, 8), (4,2)(4, 2), and (5,5)(5, 5). In each pair, one number is divisible by the other, so we do not perform any operations.

In the second example, we add 33 to the first number and 11 to the last one. We obtain the new array: [10,2,6,3,5,9][10, 2, 6, 3, 5, 9]. After that, we split the numbers into pairs (2,6)(2, 6), (3,9)(3, 9), and (10,5)(10, 5). The total number of operations is $3+1 = 4 \leq \left\lfloor \frac{x}{2} \right\rfloor = 4$. Note that this is not the minimum possible number of operations.

Scoring

  • (66 points): t=1t = 1, n4n \le 4, bi50b_i \le 50.
  • (77 points): t=1t = 1, n10n \le 10, bi104b_i \le 10^4.
  • (77 points): t=1t = 1, n10n \le 10.
  • (1010 points): bix2b_i \ge \left\lceil \frac{x}{2} \right\rceil for all ii.
  • (1010 points): for each ii, either bix6b_i \le \left\lfloor \frac{x}{6} \right\rfloor or bixx6b_i \ge x - \left\lfloor \frac{x}{6} \right\rfloor.
  • (1010 points): the answer can be obtained without performing any operations. All numbers are powers of prime numbers, all numbers do not exceed 10610^6, t10t \le 10.
  • (1313 points): the answer can be obtained without performing any operations. Each number is a product of at most two prime numbers, each prime number appears in the factorization of all numbers in total at most twice, all numbers do not exceed 10610^6, t10t \le 10.
  • (1717 points): There exists an answer where the adjacent numbers of the initial array can be paired: (1,2),(3,4),,(2n1,2n)(1, 2), (3, 4), \ldots, (2n - 1, 2n). Also, n1000\sum n \le 1000 and bi109b_i \le 10^9.
  • (2020 points): no additional constraints.