CF1632B.Roof Construction

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

It has finally been decided to build a roof over the football field in School 179. Its construction will require placing nn consecutive vertical pillars. Furthermore, the headmaster wants the heights of all the pillars to form a permutation pp of integers from 00 to n−1n - 1, where pip_i is the height of the ii-th pillar from the left (1≤i≤n)(1 \le i \le n).

As the chief, you know that the cost of construction of consecutive pillars is equal to the maximum value of the bitwise XOR of heights of all pairs of adjacent pillars. In other words, the cost of construction is equal to max⁡1≤i≤n−1pi⊕pi+1\max\limits_{1 \le i \le n - 1}{p_i \oplus p_{i + 1}}, where ⊕\oplus denotes the bitwise XOR operation.

Find any sequence of pillar heights pp of length nn with the smallest construction cost.

In this problem, a permutation is an array consisting of nn distinct integers from 00 to n−1n - 1 in arbitrary order. For example, [2,3,1,0,4][2,3,1,0,4] is a permutation, but [1,0,1][1,0,1] is not a permutation (11 appears twice in the array) and [1,0,3][1,0,3] is also not a permutation (n=3n=3, but 33 is in the array).

最终决定为第179中学的足球场建造一个顶棚。其施工需要安装 nn 根连续的垂直支柱。此外,校长希望所有支柱的高度构成一个 00 到 n−1n - 1 的排列 pp,其中 pip_i 表示从左往右数第 ii 根支柱的高度(1≤i≤n1 \le i \le n)。

作为总工程师,您知道:连续支柱的施工成本等于所有相邻支柱高度对的按位异或(XOR)值中的最大值。换言之,施工成本等于 max⁡1≤i≤n−1pi⊕pi+1\max\limits_{1 \le i \le n - 1}{p_i \oplus p_{i + 1}},其中 ⊕\oplus 表示按位异或运算。

请找出任意一个长度为 nn 的支柱高度序列 pp,使其施工成本最小。

在本题中,排列指由 00 到 n−1n - 1 这 nn 个互不相同的整数以任意顺序组成的数组。例如,[2,3,1,0,4][2,3,1,0,4] 是一个排列;而 [1,0,1][1,0,1] 不是排列(数字 11 在数组中出现了两次),[1,0,3][1,0,3] 也不是排列(此时 n=3n = 3,但数组中却包含了 33)。

输入格式

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

The only line for each test case contains a single integer nn (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5) — the number of pillars for the construction of the roof.

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)。随后是各测试用例的描述。

每个测试用例仅一行,包含一个整数 nn(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5)——表示用于建造屋顶的柱子数量。

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

输出格式

For each test case print nn integers p1p_1, p2p_2, …\ldots, pnp_n — the sequence of pillar heights with the smallest construction cost.

If there are multiple answers, print any of them.

对于每个测试用例,输出 nn 个整数 p1p_1, p2p_2, …\ldots, pnp_n —— 即构造成本最小的柱子高度序列。

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

输入输出样例

  • 输入#1

    4
    2
    3
    5
    10

    输出#1

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

说明/提示

For n=2n = 2 there are 22 sequences of pillar heights:

  • [0,1][0, 1] — cost of construction is 0⊕1=10 \oplus 1 = 1.
  • [1,0][1, 0] — cost of construction is 1⊕0=11 \oplus 0 = 1.

For n=3n = 3 there are 66 sequences of pillar heights:

  • [0,1,2][0, 1, 2] — cost of construction is max⁡(0⊕1,1⊕2)=max⁡(1,3)=3\max(0 \oplus 1, 1 \oplus 2) = \max(1, 3) = 3.
  • [0,2,1][0, 2, 1] — cost of construction is max⁡(0⊕2,2⊕1)=max⁡(2,3)=3\max(0 \oplus 2, 2 \oplus 1) = \max(2, 3) = 3.
  • [1,0,2][1, 0, 2] — cost of construction is max⁡(1⊕0,0⊕2)=max⁡(1,2)=2\max(1 \oplus 0, 0 \oplus 2) = \max(1, 2) = 2.
  • [1,2,0][1, 2, 0] — cost of construction is max⁡(1⊕2,2⊕0)=max⁡(3,2)=3\max(1 \oplus 2, 2 \oplus 0) = \max(3, 2) = 3.
  • [2,0,1][2, 0, 1] — cost of construction is max⁡(2⊕0,0⊕1)=max⁡(2,1)=2\max(2 \oplus 0, 0 \oplus 1) = \max(2, 1) = 2.
  • [2,1,0][2, 1, 0] — cost of construction is max⁡(2⊕1,1⊕0)=max⁡(3,1)=3\max(2 \oplus 1, 1 \oplus 0) = \max(3, 1) = 3.

当 n=2n = 2 时,存在 22 种柱子高度序列:

  • [0,1][0, 1] — 建造成本为 0⊕1=10 \oplus 1 = 1。
  • [1,0][1, 0] — 建造成本为 1⊕0=11 \oplus 0 = 1。

当 n=3n = 3 时,存在 66 种柱子高度序列:

  • [0,1,2][0, 1, 2] — 建造成本为 max⁡(0⊕1,1⊕2)=max⁡(1,3)=3\max(0 \oplus 1, 1 \oplus 2) = \max(1, 3) = 3。
  • [0,2,1][0, 2, 1] — 建造成本为 max⁡(0⊕2,2⊕1)=max⁡(2,3)=3\max(0 \oplus 2, 2 \oplus 1) = \max(2, 3) = 3。
  • [1,0,2][1, 0, 2] — 建造成本为 max⁡(1⊕0,0⊕2)=max⁡(1,2)=2\max(1 \oplus 0, 0 \oplus 2) = \max(1, 2) = 2。
  • [1,2,0][1, 2, 0] — 建造成本为 max⁡(1⊕2,2⊕0)=max⁡(3,2)=3\max(1 \oplus 2, 2 \oplus 0) = \max(3, 2) = 3。
  • [2,0,1][2, 0, 1] — 建造成本为 max⁡(2⊕0,0⊕1)=max⁡(2,1)=2\max(2 \oplus 0, 0 \oplus 1) = \max(2, 1) = 2。
  • [2,1,0][2, 1, 0] — 建造成本为 max⁡(2⊕1,1⊕0)=max⁡(3,1)=3\max(2 \oplus 1, 1 \oplus 0) = \max(3, 1) = 3。

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

首页