CF1869A.Make It Zero

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

During Zhongkao examination, Reycloer met an interesting problem, but he cannot come up with a solution immediately. Time is running out! Please help him.

Initially, you are given an array aa consisting of n≥2n \ge 2 integers, and you want to change all elements in it to 00.

In one operation, you select two indices ll and rr (1≤l≤r≤n1\le l\le r\le n) and do the following:

  • Let s=al⊕al+1⊕…⊕ars=a_l\oplus a_{l+1}\oplus \ldots \oplus a_r, where ⊕\oplus denotes the bitwise XOR operation;
  • Then, for all l≤i≤rl\le i\le r, replace aia_i with ss.

You can use the operation above in any order at most 88 times in total.

Find a sequence of operations, such that after performing the operations in order, all elements in aa are equal to 00. It can be proven that the solution always exists.

在中考考试中,Reycloer 遇到了一道有趣的题目,但他一时无法想出解法。时间正在飞速流逝!请帮助他。

初始时,你被给定一个由 n≥2n \ge 2 个整数组成的数组 aa,你的目标是将其中所有元素都变为 00。

每次操作中,你需要选择两个下标 ll 和 rr(满足 1≤l≤r≤n1\le l\le r\le n),并执行以下步骤:

  • 计算 s=al⊕al+1⊕…⊕ars=a_l\oplus a_{l+1}\oplus \ldots \oplus a_r,其中 ⊕\oplus 表示按位异或运算;
  • 然后,对所有满足 l≤i≤rl\le i\le r 的下标 ii,将 aia_i 替换为 ss。

你最多可执行上述操作 88 次(操作顺序可任意安排)。

请找出一组操作序列,使得按该顺序执行完所有操作后,数组 aa 中所有元素均为 00。可以证明,这样的解总是存在的。

输入格式

The first line of input contains a single integer tt (1≤t≤5001\le t\le 500) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer nn (2≤n≤1002\le n\le 100) — the length of the array aa.

The second line of each test case contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n (0≤ai≤1000\le a_i\le 100) — the elements of the array aa.

输入的第一行包含一个整数 tt(1≤t≤5001\le t\le 500),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤1002\le n\le 100),表示数组 aa 的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n(0≤ai≤1000\le a_i\le 100),表示数组 aa 的元素。

输出格式

For each test case, in the first line output a single integer kk (0≤k≤80\le k\le 8) — the number of operations you use.

Then print kk lines, in the ii-th line output two integers lil_i and rir_i (1≤li≤ri≤n1\le l_i\le r_i\le n) representing that you select lil_i and rir_i in the ii-th operation.

Note that you do not have to minimize kk. If there are multiple solutions, you may output any of them.

对于每个测试用例,在第一行输出一个整数 kk(0≤k≤80\le k\le 8)—— 表示你所使用的操作次数。

然后输出 kk 行,其中第 ii 行输出两个整数 lil_i 和 rir_i(1≤li≤ri≤n1\le l_i\le r_i\le n),表示你在第 ii 次操作中选择 lil_i 和 rir_i。

注意:你无需最小化 kk。若存在多种解,你可以输出其中任意一种。

输入输出样例

  • 输入#1

    6
    4
    1 2 3 0
    8
    3 1 4 1 5 9 2 6
    6
    1 5 4 1 4 7
    5
    0 0 0 0 0
    7
    1 1 9 9 0 1 8
    3
    100 100 0

    输出#1

    1
    1 4
    2
    4 7
    1 8
    6
    1 2
    3 4
    5 6
    1 3
    4 6
    1 6
    0
    4
    1 2
    6 7
    3 4
    6 7
    1
    1 2

说明/提示

In the first test case, since 1⊕2⊕3⊕0=01\oplus2\oplus3\oplus0=0, after performing the operation on segment [1,4][1,4], all the elements in the array are equal to 00.

In the second test case, after the first operation, the array becomes equal to [3,1,4,15,15,15,15,6][3,1,4,15,15,15,15,6], after the second operation, the array becomes equal to [0,0,0,0,0,0,0,0][0,0,0,0,0,0,0,0].

In the third test case:

Operation

aa before

aa after

11

[1,5‾,4,1,4,7][\underline{1,5},4,1,4,7]

→\rightarrow

[4,4,4,1,4,7][4,4,4,1,4,7]

22

[4,4,4,1‾,4,7][4,4,\underline{4,1},4,7]

→\rightarrow

[4,4,5,5,4,7][4,4,5,5,4,7]

33

[4,4,5,5,4,7‾][4,4,5,5,\underline{4,7}]

→\rightarrow

[4,4,5,5,3,3][4,4,5,5,3,3]

44

[4,4,5‾,5,3,3][\underline{4,4,5},5,3,3]

→\rightarrow

[5,5,5,5,3,3][5,5,5,5,3,3]

55

[5,5,5,5,3,3‾][5,5,5,\underline{5,3,3}]

→\rightarrow

[5,5,5,5,5,5][5,5,5,5,5,5]

66

[5,5,5,5,5,5‾][\underline{5,5,5,5,5,5}]

→\rightarrow

[0,0,0,0,0,0][0,0,0,0,0,0]

In the fourth test case, the initial array contains only 00, so we do not need to perform any operations with it.

在第一个测试用例中,由于 1⊕2⊕3⊕0=01\oplus2\oplus3\oplus0=0,对区间 [1,4][1,4] 执行操作后,数组中的所有元素均变为 00。

在第二个测试用例中,第一次操作后,数组变为 [3,1,4,15,15,15,15,6][3,1,4,15,15,15,15,6];第二次操作后,数组变为 [0,0,0,0,0,0,0,0][0,0,0,0,0,0,0,0]。

在第三个测试用例中:

操作

操作前的 aa

操作后的 aa

11

[1,5‾,4,1,4,7][\underline{1,5},4,1,4,7]

→\rightarrow

[4,4,4,1,4,7][4,4,4,1,4,7]

22

[4,4,4,1‾,4,7][4,4,\underline{4,1},4,7]

→\rightarrow

[4,4,5,5,4,7][4,4,5,5,4,7]

33

[4,4,5,5,4,7‾][4,4,5,5,\underline{4,7}]

→\rightarrow

[4,4,5,5,3,3][4,4,5,5,3,3]

44

[4,4,5‾,5,3,3][\underline{4,4,5},5,3,3]

→\rightarrow

[5,5,5,5,3,3][5,5,5,5,3,3]

55

[5,5,5,5,3,3‾][5,5,5,\underline{5,3,3}]

→\rightarrow

[5,5,5,5,5,5][5,5,5,5,5,5]

66

[5,5,5,5,5,5‾][\underline{5,5,5,5,5,5}]

→\rightarrow

[0,0,0,0,0,0][0,0,0,0,0,0]

在第四个测试用例中,初始数组仅包含 00,因此无需对其执行任何操作。

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

首页