CF1338C.Perfect Triples

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Consider the infinite sequence ss of positive integers, created by repeating the following steps:

  1. Find the lexicographically smallest triple of positive integers (a,b,c)(a, b, c) such that
    • a⊕b⊕c=0a \oplus b \oplus c = 0, where ⊕\oplus denotes the bitwise XOR operation.
    • aa, bb, cc are not in ss.Here triple of integers (a1,b1,c1)(a_1, b_1, c_1) is considered to be lexicographically smaller than triple (a2,b2,c2)(a_2, b_2, c_2) if sequence [a1,b1,c1][a_1, b_1, c_1] is lexicographically smaller than sequence [a2,b2,c2][a_2, b_2, c_2].
  2. Append aa, bb, cc to ss in this order.
  3. Go back to the first step.

You have integer nn. Find the nn-th element of ss.

You have to answer tt independent test cases.

A sequence aa is lexicographically smaller than a sequence bb if in the first position where aa and bb differ, the sequence aa has a smaller element than the corresponding element in bb.

考虑由以下步骤重复生成的正整数无限序列 ss:

  1. 找到字典序最小的正整数三元组 (a,b,c)(a, b, c),满足:
    • a⊕b⊕c=0a \oplus b \oplus c = 0,其中 ⊕\oplus 表示按位异或运算;
    • aa、bb、cc 均尚未出现在序列 ss 中。
      这里,三元组 (a1,b1,c1)(a_1, b_1, c_1) 被认为字典序小于三元组 (a2,b2,c2)(a_2, b_2, c_2),当且仅当序列 [a1,b1,c1][a_1, b_1, c_1] 字典序小于序列 [a2,b2,c2][a_2, b_2, c_2]。
  2. 将 aa、bb、cc 按此顺序追加到 ss 的末尾。
  3. 返回第 1 步继续执行。

给定整数 nn,求序列 ss 的第 nn 个元素。

你需要回答 tt 个相互独立的测试用例。

序列 aa 字典序小于序列 bb,当且仅当在 aa 与 bb 首次出现差异的位置上,aa 在该位置的元素小于 bb 在对应位置的元素。

输入格式

The first line contains a single integer tt (1≤t≤1051 \le t \le 10^5) — the number of test cases.

Each of the next tt lines contains a single integer nn (1≤n≤10161\le n \le 10^{16}) — the position of the element you want to know.

第一行包含一个整数 tt(1≤t≤1051 \le t \le 10^5)—— 测试用例的数量。

接下来的 tt 行中,每行包含一个整数 nn(1≤n≤10161\le n \le 10^{16})—— 你要查询的元素的位置。

输出格式

In each of the tt lines, output the answer to the corresponding test case.

在每行的 tt 行中,输出对应测试用例的答案。

输入输出样例

  • 输入#1

    9
    1
    2
    3
    4
    5
    6
    7
    8
    9

    输出#1

    1
    2
    3
    4
    8
    12
    5
    10
    15

说明/提示

The first elements of ss are $1, 2, 3, 4, 8, 12, 5, 10, 15, \dots $

序列 ss 的前若干项为 $1, 2, 3, 4, 8, 12, 5, 10, 15, \dots $

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

首页