CF1718A1.Burenka and Traditions (easy version)

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

This is the easy version of this problem. The difference between easy and hard versions is only the constraints on aia_i and on nn. You can make hacks only if both versions of the problem are solved.

Burenka is the crown princess of Buryatia, and soon she will become the nn-th queen of the country. There is an ancient tradition in Buryatia — before the coronation, the ruler must show their strength to the inhabitants. To determine the strength of the nn-th ruler, the inhabitants of the country give them an array of aa of exactly nn numbers, after which the ruler must turn all the elements of the array into zeros in the shortest time. The ruler can do the following two-step operation any number of times:

  • select two indices ll and rr, so that 1≤l≤r≤n1 \le l \le r \le n and a non-negative integer xx, then
  • for all l≤i≤rl \leq i \leq r assign ai:=ai⊕xa_i := a_i \oplus x, where ⊕\oplus denotes the bitwise XOR operation. It takes ⌈r−l+12⌉\left\lceil \frac{r-l+1}{2} \right\rceil seconds to do this operation, where ⌈y⌉\lceil y \rceil denotes yy rounded up to the nearest integer.

Help Burenka calculate how much time she will need.

这是本题的简单版本。简单版本与困难版本的唯一区别在于对 aia_i 和 nn 的约束条件不同。仅当两个版本均被解决时,才允许进行 hack。

布尔恩卡是布里亚特共和国的王储,她即将成为该国第 nn 任女王。布里亚特共和国有一项古老传统:加冕前,统治者必须向国民展示自己的实力。为判定第 nn 任统治者的实力,国民会给出一个恰好包含 nn 个数的数组 aa,随后统治者需在最短时间内将该数组的所有元素全部变为零。统治者可以执行以下两步操作任意多次:

  • 选择两个下标 ll 和 rr,满足 1≤l≤r≤n1 \le l \le r \le n,以及一个非负整数 xx,然后
  • 对所有满足 l≤i≤rl \leq i \leq r 的下标 ii,令 ai:=ai⊕xa_i := a_i \oplus x,其中 ⊕\oplus 表示按位异或运算。该操作耗时 ⌈r−l+12⌉\left\lceil \frac{r-l+1}{2} \right\rceil 秒,其中 ⌈y⌉\lceil y \rceil 表示将 yy 向上取整(即不小于 yy 的最小整数)。

请帮助布尔恩卡计算她完成任务所需的最短时间。

输入格式

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

The first line of each test case contains a single integer nn (1≤n≤50001 \le n \le 5000) — the size of the array.

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

It is guaranteed that the sum of nn in all tests does not exceed 50005000.

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

每个测试用例的第一行包含一个整数 nn(1≤n≤50001 \le n \le 5000)—— 表示数组的大小。

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

保证所有测试用例中 nn 的总和不超过 50005000。

输出格式

For each test case, output a single number — the minimum time that Burenka will need.

对于每个测试用例,输出一个数字——Burenka 所需的最少时间。

输入输出样例

  • 输入#1

    7
    4
    5 5 5 5
    3
    1 3 2
    2
    0 0
    3
    2 5 7
    6
    1 2 3 3 2 1
    10
    27 27 34 32 2 31 23 56 52 4
    5
    1822 1799 57 23 55

    输出#1

    2
    2
    0
    2
    4
    7
    4

说明/提示

In the first test case, Burenka can choose segment l=1l = 1, r=4r = 4, and x=5x=5. so it will fill the array with zeros in 22 seconds.

In the second test case, Burenka first selects segment l=1l = 1, r=2r = 2, and x=1x = 1, after which a=[0,2,2]a = [0, 2, 2], and then the segment l=2l = 2, r=3r = 3, and x=2x=2, which fills the array with zeros. In total, Burenka will spend 22 seconds.

在第一个测试用例中,Burenka 可以选择区间 l=1l = 1、r=4r = 4,以及 x=5x=5,这样她将在 22 秒内将数组全部填为零。

在第二个测试用例中,Burenka 首先选择区间 l=1l = 1、r=2r = 2,以及 x=1x = 1,操作后数组变为 a=[0,2,2]a = [0, 2, 2];然后她再选择区间 l=2l = 2、r=3r = 3,以及 x=2x=2,从而将整个数组填为零。总计,Burenka 将花费 22 秒。

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

首页