CF1748F.Circular Xor Reversal
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have an array a0,a1,…,an−1 of length n. Initially, ai=2i for all 0≤i<n. Note that array a is zero-indexed.
You want to reverse this array (that is, make ai equal to 2n−1−i for all 0≤i<n). To do this, you can perform the following operation no more than 250000 times:
- Select an integer i (0≤i<n) and replace ai by ai⊕a(i+1)modn.
Here, ⊕ denotes the bitwise XOR operation.
Your task is to find any sequence of operations that will result in the array a being reversed. It can be shown that under the given constraints, a solution always exists.
你有一个长度为 n 的数组 a0,a1,…,an−1。初始时,对所有 0≤i<n,有 ai=2i。注意:数组 a 是从零开始索引的。
你希望将该数组反转(即,使得对所有 0≤i<n,均有 ai=2n−1−i)。为此,你可以执行以下操作,至多 250000 次:
- 选择一个整数 i(满足 0≤i<n),并将 ai 替换为 ai⊕a(i+1)modn。
其中,⊕ 表示按位异或运算。
你的任务是找出任意一个操作序列,使得最终数组 a 被成功反转。在给定约束下,可以证明解一定存在。
输入格式
The first line contains a single integer n (2≤n≤400) — the length of the array a.
第一行包含一个整数 n(2≤n≤400)—— 数组 a 的长度。
输出格式
On the first line print one integer k (0≤k≤250000) — the number of operations performed.
On the second line print k integers i1,i2,…,ik (0≤ij<n). Here, ij should be the integer selected on the j-th operation.
Note that you don't need to minimize the number of operations.
第一行输出一个整数 k(0≤k≤250000)—— 执行的操作次数。
第二行输出 k 个整数 i1,i2,…,ik(0≤ij<n)。其中,ij 表示第 j 次操作中所选的整数。
注意:你无需最小化操作次数。
输入输出样例
输入#1
2
输出#1
3 1 0 1
输入#2
3
输出#2
9 1 0 1 0 2 1 0 1 0
说明/提示
In the notes, the elements on which the operations are performed are colored red.
In the first test case, array a will change in the following way:
[1,2]→[1,3]→[2,3]→[2,1].
In the second test case, array a will change in the following way:
[1,2,4]→[1,6,4]→[7,6,4]→[7,2,4]→[5,2,4]→[5,2,1]→[5,3,1]→[6,3,1]→[6,2,1]→[4,2,1].
在讲义中,执行操作的元素以红色标出。
在第一个测试用例中,数组 a 将按如下方式变化:
[1,2]→[1,3]→[2,3]→[2,1]。
在第二个测试用例中,数组 a 将按如下方式变化:
[1,2,4]→[1,6,4]→[7,6,4]→[7,2,4]→[5,2,4]→[5,2,1]→[5,3,1]→[6,3,1]→[6,2,1]→[4,2,1]。
输入解题思路,AI测评打分。不知道怎么写?