[CF2147B]Multiple Construction题解

time limit per test

1 second

memory limit per test

256 megabytes

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 整除。

可以证明解总是存在的。

Input

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 。

Output

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 整数的一行,即满足给定条件的数组。

如果有多个有效答案,打印其中任何一个。

Example

Input

Copy

3
2
3
1

Output

Copy

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

Note

Visualizer link

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.

有道 翻译

注意

(可视化工具链接)(https://codeforces.com/assets/contests/2147/B_RlbLXHyL5DuDqDlx4DG1.html)

在第一个测试用例中:

—数字 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 的倍数。

思路

n~1+n+1~n-1

代码见下

#include<bits/stdc++.h>
using namespace std;
long long t,n,ff=0;
int main(){
	cin>>t;
	while(t--){
		cin>>n;
		for(int i=n;i>=1;i--){
			cout<<i<<" ";
		}
		cout<<n<<" ";
		for(int i=1;i<=n-1;i++){
			cout<<i<<" ";
		}
		cout<<endl;
	}
	return 0;
}

posted @ 2025-10-16 10:34  bz02_2023f2  阅读(8)  评论(0)    收藏  举报  来源