CF1748F.Circular Xor Reversal

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You have an array a0,a1,…,an−1a_0, a_1, \ldots, a_{n-1} of length nn. Initially, ai=2ia_i = 2^i for all 0≤i<n0 \le i \lt n. Note that array aa is zero-indexed.

You want to reverse this array (that is, make aia_i equal to 2n−1−i2^{n-1-i} for all 0≤i<n0 \le i \lt n). To do this, you can perform the following operation no more than 250 000250\,000 times:

  • Select an integer ii (0≤i<n0 \le i \lt n) and replace aia_i by ai⊕a(i+1) mod na_i \oplus a_{(i+1)\bmod n}.

Here, ⊕\oplus denotes the bitwise XOR operation.

Your task is to find any sequence of operations that will result in the array aa being reversed. It can be shown that under the given constraints, a solution always exists.

你有一个长度为 nn 的数组 a0,a1,…,an−1a_0, a_1, \ldots, a_{n-1}。初始时,对所有 0≤i<n0 \le i \lt n,有 ai=2ia_i = 2^i。注意:数组 aa 是从零开始索引的。

你希望将该数组反转(即,使得对所有 0≤i<n0 \le i \lt n,均有 ai=2n−1−ia_i = 2^{n-1-i})。为此,你可以执行以下操作,至多 250 000250\,000 次:

  • 选择一个整数 ii(满足 0≤i<n0 \le i \lt n),并将 aia_i 替换为 ai⊕a(i+1) mod na_i \oplus a_{(i+1)\bmod n}。

其中,⊕\oplus 表示按位异或运算。

你的任务是找出任意一个操作序列,使得最终数组 aa 被成功反转。在给定约束下,可以证明解一定存在。

输入格式

The first line contains a single integer nn (2≤n≤4002 \le n \le 400) — the length of the array aa.

第一行包含一个整数 nn(2≤n≤4002 \le n \le 400)—— 数组 aa 的长度。

输出格式

On the first line print one integer kk (0≤k≤250 0000 \le k \le 250\,000) — the number of operations performed.

On the second line print kk integers i1,i2,…,iki_1,i_2,\ldots,i_k (0≤ij<n0 \le i_j \lt n). Here, iji_j should be the integer selected on the jj-th operation.

Note that you don't need to minimize the number of operations.

第一行输出一个整数 kk(0≤k≤250 0000 \le k \le 250\,000)—— 执行的操作次数。

第二行输出 kk 个整数 i1,i2,…,iki_1,i_2,\ldots,i_k(0≤ij<n0 \le i_j \lt n)。其中,iji_j 表示第 jj 次操作中所选的整数。

注意:你无需最小化操作次数。

输入输出样例

  • 输入#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 aa will change in the following way:

[1,2]→[1,3]→[2,3]→[2,1][1,\color{red}{2}] \rightarrow [\color{red}{1},3] \rightarrow [2,\color{red}{3}] \rightarrow [2,1].

In the second test case, array aa 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][1,\color{red}{2},4] \rightarrow [\color{red}{1},6,4] \rightarrow [7,\color{red}{6},4] \rightarrow [\color{red}{7},2,4] \rightarrow [5,2,\color{red}{4}] \rightarrow [5,\color{red}{2},1] \rightarrow [\color{red}{5},3,1] \rightarrow [6,\color{red}{3},1] \rightarrow [\color{red}{6},2,1] \rightarrow [4,2,1].

在讲义中,执行操作的元素以红色标出。

在第一个测试用例中,数组 aa 将按如下方式变化:

[1,2]→[1,3]→[2,3]→[2,1][1,\color{red}{2}] \rightarrow [\color{red}{1},3] \rightarrow [2,\color{red}{3}] \rightarrow [2,1]。

在第二个测试用例中,数组 aa 将按如下方式变化:

[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][1,\color{red}{2},4] \rightarrow [\color{red}{1},6,4] \rightarrow [7,\color{red}{6},4] \rightarrow [\color{red}{7},2,4] \rightarrow [5,2,\color{red}{4}] \rightarrow [5,\color{red}{2},1] \rightarrow [\color{red}{5},3,1] \rightarrow [6,\color{red}{3},1] \rightarrow [\color{red}{6},2,1] \rightarrow [4,2,1]。

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

首页