CF2147B.Multiple Construction
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an integer n. Your task is to construct an array of length 2⋅n such that:
- Each integer from 1 to n appears exactly twice in the array.
- For each integer x (1≤x≤n), the distance between the two occurrences of x is a multiple of x. In other words, if px and qx are the indices of the two occurrences of x, ∣qx−px∣ must be divisible by x.
It can be shown that a solution always exists.
给你一个整数 n。你的任务是构造一个长度为 2⋅n 的数组,满足以下条件:
- 每个从 1 到 n 的整数在数组中恰好出现两次。
- 对于每个整数 x(1≤x≤n),x 的两次出现位置之间的距离是 x 的倍数。换言之,若 px 和 qx 分别表示 x 的两次出现位置的下标,则 ∣qx−px∣ 必须能被 x 整除。
可以证明,这样的解总是存在的。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
Each of the next t lines contains a single integer n (1≤n≤2⋅105).
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是测试用例的描述。
接下来的 t 行中,每行包含一个整数 n(1≤n≤2⋅105)。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
For each test case, print a line containing 2⋅n integers — the array that satisfies the given conditions.
If there are multiple valid answers, print any of them.
对于每个测试用例,输出一行包含 2⋅n 个整数的数组——该数组需满足给定的条件。
若存在多个合法答案,输出其中任意一个即可。
输入输出样例
输入#1
3 2 3 1
输出#1
1 2 1 2 1 3 1 2 3 2 1 1
说明/提示
In the first test case:
- The number 1 appears at positions 1 and 3: the distance is 2, which is divisible by 1.
- The number 2 appears at positions 2 and 4: the distance is 2, which is divisible by 2.
In the second test case:
- The number 1 appears at positions 1 and 3: the distance is 2, which is divisible by 1.
- The number 2 appears at positions 4 and 6: the distance is 2, which is divisible by 2.
- The number 3 appears at positions 2 and 5: the distance is 3, which is divisible by 3.
In the third test case, the two occurrences of 1 are at positions 1 and 2, so the distance between them is 1, which is a multiple of 1.
在第一个测试用例中:
- 数字 1 出现在位置 1 和 3:距离为 2,可被 1 整除。
- 数字 2 出现在位置 2 和 4:距离为 2,可被 2 整除。
在第二个测试用例中:
- 数字 1 出现在位置 1 和 3:距离为 2,可被 1 整除。
- 数字 2 出现在位置 4 和 6:距离为 2,可被 2 整除。
- 数字 3 出现在位置 2 和 5:距离为 3,可被 3 整除。
在第三个测试用例中,数字 1 的两次出现位置分别为 1 和 2,因此它们之间的距离为 1,是 1 的倍数。
输入解题思路,AI测评打分。不知道怎么写?