CF1338C.Perfect Triples
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Consider the infinite sequence s of positive integers, created by repeating the following steps:
- Find the lexicographically smallest triple of positive integers (a,b,c) such that
- a⊕b⊕c=0, where ⊕ denotes the bitwise XOR operation.
- a, b, c are not in s.Here triple of integers (a1,b1,c1) is considered to be lexicographically smaller than triple (a2,b2,c2) if sequence [a1,b1,c1] is lexicographically smaller than sequence [a2,b2,c2].
- Append a, b, c to s in this order.
- Go back to the first step.
You have integer n. Find the n-th element of s.
You have to answer t independent test cases.
A sequence a is lexicographically smaller than a sequence b if in the first position where a and b differ, the sequence a has a smaller element than the corresponding element in b.
考虑由以下步骤重复生成的正整数无限序列 s:
- 找到字典序最小的正整数三元组 (a,b,c),满足:
- a⊕b⊕c=0,其中 ⊕ 表示按位异或运算;
- a、b、c 均尚未出现在序列 s 中。
这里,三元组 (a1,b1,c1) 被认为字典序小于三元组 (a2,b2,c2),当且仅当序列 [a1,b1,c1] 字典序小于序列 [a2,b2,c2]。
- 将 a、b、c 按此顺序追加到 s 的末尾。
- 返回第 1 步继续执行。
给定整数 n,求序列 s 的第 n 个元素。
你需要回答 t 个相互独立的测试用例。
序列 a 字典序小于序列 b,当且仅当在 a 与 b 首次出现差异的位置上,a 在该位置的元素小于 b 在对应位置的元素。
输入格式
The first line contains a single integer t (1≤t≤105) — the number of test cases.
Each of the next t lines contains a single integer n (1≤n≤1016) — the position of the element you want to know.
第一行包含一个整数 t(1≤t≤105)—— 测试用例的数量。
接下来的 t 行中,每行包含一个整数 n(1≤n≤1016)—— 你要查询的元素的位置。
输出格式
In each of the t lines, output the answer to the corresponding test case.
在每行的 t 行中,输出对应测试用例的答案。
输入输出样例
输入#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 s are $1, 2, 3, 4, 8, 12, 5, 10, 15, \dots $
序列 s 的前若干项为 $1, 2, 3, 4, 8, 12, 5, 10, 15, \dots $
输入解题思路,AI测评打分。不知道怎么写?