CF1748F.Circular Xor Reversal
普及/提高-
通过率:0%
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.
输入格式
The first line contains a single integer n ( 2≤n≤400 ) — the length of the array 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.
输入输出样例
输入#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] .