CF2147B.Multiple Construction

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an integer nn. Your task is to construct an array of length 2⋅n2 \cdot n such that:

  • Each integer from 11 to nn appears exactly twice in the array.
  • For each integer xx (1≤x≤n1 \le x \le n), the distance between the two occurrences of xx is a multiple of xx. In other words, if pxp_x and qxq_x are the indices of the two occurrences of xx, ∣qx−px∣| q_x - p_x | must be divisible by xx.

It can be shown that a solution always exists.

给你一个整数 nn。你的任务是构造一个长度为 2⋅n2 \cdot n 的数组,满足以下条件:

  • 每个从 11 到 nn 的整数在数组中恰好出现两次。
  • 对于每个整数 xx(1≤x≤n1 \le x \le n),xx 的两次出现位置之间的距离是 xx 的倍数。换言之,若 pxp_x 和 qxq_x 分别表示 xx 的两次出现位置的下标,则 ∣qx−px∣| q_x - p_x | 必须能被 xx 整除。

可以证明,这样的解总是存在的。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

Each of the next tt lines contains a single integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^{5}).

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^{5}.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是测试用例的描述。

接下来的 tt 行中,每行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^{5})。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^{5}。

输出格式

For each test case, print a line containing 2⋅n2 \cdot n integers — the array that satisfies the given conditions.

If there are multiple valid answers, print any of them.

对于每个测试用例,输出一行包含 2⋅n2 \cdot n 个整数的数组——该数组需满足给定的条件。

若存在多个合法答案,输出其中任意一个即可。

输入输出样例

  • 输入#1

    3
    2
    3
    1

    输出#1

    1 2 1 2
    1 3 1 2 3 2
    1 1

说明/提示

Visualizer link

In the first test case:

  • The number 11 appears at positions 11 and 33: the distance is 22, which is divisible by 11.
  • The number 22 appears at positions 22 and 44: the distance is 22, which is divisible by 22.

In the second test case:

  • The number 11 appears at positions 11 and 33: the distance is 22, which is divisible by 11.
  • The number 22 appears at positions 44 and 66: the distance is 22, which is divisible by 22.
  • The number 33 appears at positions 22 and 55: the distance is 33, which is divisible by 33.

In the third test case, the two occurrences of 11 are at positions 11 and 22, so the distance between them is 11, which is a multiple of 11.

可视化链接

在第一个测试用例中:

  • 数字 11 出现在位置 11 和 33:距离为 22,可被 11 整除。
  • 数字 22 出现在位置 22 和 44:距离为 22,可被 22 整除。

在第二个测试用例中:

  • 数字 11 出现在位置 11 和 33:距离为 22,可被 11 整除。
  • 数字 22 出现在位置 44 和 66:距离为 22,可被 22 整除。
  • 数字 33 出现在位置 22 和 55:距离为 33,可被 33 整除。

在第三个测试用例中,数字 11 的两次出现位置分别为 11 和 22,因此它们之间的距离为 11,是 11 的倍数。

输入解题思路,AI测评打分。不知道怎么写?

首页