CF1731C.Even Subarrays

普及+/提高

通过率:0%

时间限制:2.50s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an integer array a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤n1 \le a_i \le n).

Find the number of subarrays of aa whose XOR⁡\operatorname{XOR} has an even number of divisors. In other words, find all pairs of indices (i,j)(i, j) (i≤ji \le j) such that ai⊕ai+1⊕⋯⊕aja_i \oplus a_{i + 1} \oplus \dots \oplus a_j has an even number of divisors.

For example, numbers 22, 33, 55 or 66 have an even number of divisors, while 11 and 44 — odd. Consider that 00 has an odd number of divisors in this task.

Here XOR⁡\operatorname{XOR} (or ⊕\oplus) denotes the bitwise XOR operation.

Print the number of subarrays but multiplied by 2022... Okay, let's stop. Just print the actual answer.

给你一个整数数组 a1,a2,…,ana_1, a_2, \dots, a_n(其中 1≤ai≤n1 \le a_i \le n)。

请你找出数组 aa 中有多少个子数组,其异或值(XOR⁡\operatorname{XOR})具有偶数个正因数。换句话说,求满足条件的下标对 (i,j)(i, j)(其中 i≤ji \le j)的个数,使得 ai⊕ai+1⊕⋯⊕aja_i \oplus a_{i + 1} \oplus \dots \oplus a_j 具有偶数个正因数。

例如,数字 22、33、55 和 66 均有偶数个正因数,而 11 和 44 则有奇数个正因数。本题中规定:00 被视为具有奇数个正因数。

此处 XOR⁡\operatorname{XOR}(或记作 ⊕\oplus)表示按位异或运算。

请输出满足条件的子数组个数(注意:不要乘以 2022……好了,我们停一下。只需输出真实的答案即可)。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \leq t \leq 10^4). Description of the test cases follows.

The first line of each test case contains a single integer nn (2≤n≤2⋅1052 \leq n \leq 2 \cdot 10^5) — the length of the array aa.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤n1 \leq a_i \leq n).

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \leq t \leq 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤2⋅1052 \leq n \leq 2 \cdot 10^5)—— 表示数组 aa 的长度。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤n1 \leq a_i \leq n)。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, print the number of subarrays, whose XOR⁡\operatorname{XOR} has an even number of divisors.

对于每个测试用例,输出满足其异或(XOR⁡\operatorname{XOR})值具有偶数个约数的子数组个数。

输入输出样例

  • 输入#1

    4
    3
    3 1 2
    5
    4 2 1 5 3
    4
    4 4 4 4
    7
    5 7 3 7 1 7 3

    输出#1

    4
    11
    0
    20

说明/提示

In the first test case, there are 44 subarrays whose XOR⁡\operatorname{XOR} has an even number of divisors: [3][3], [3,1][3,1], [1,2][1,2], [2][2].

In the second test case, there are 1111 subarrays whose XOR⁡\operatorname{XOR} has an even number of divisors: [4,2][4,2], [4,2,1][4,2,1], [4,2,1,5][4,2,1,5], [2][2], [2,1][2,1], [2,1,5][2,1,5], [2,1,5,3][2,1,5,3], [1,5,3][1,5,3], [5][5], [5,3][5,3], [3][3].

In the third test case, there is no subarray whose XOR⁡\operatorname{XOR} has an even number of divisors since XOR⁡\operatorname{XOR} of any subarray is either 44 or 00.

在第一个测试用例中,有 44 个子数组的异或值(XOR⁡\operatorname{XOR})具有偶数个约数:[3][3]、[3,1][3,1]、[1,2][1,2]、[2][2]。

在第二个测试用例中,有 1111 个子数组的异或值(XOR⁡\operatorname{XOR})具有偶数个约数:[4,2][4,2]、[4,2,1][4,2,1]、[4,2,1,5][4,2,1,5]、[2][2]、[2,1][2,1]、[2,1,5][2,1,5]、[2,1,5,3][2,1,5,3]、[1,5,3][1,5,3]、[5][5]、[5,3][5,3]、[3][3]。

在第三个测试用例中,不存在异或值(XOR⁡\operatorname{XOR})具有偶数个约数的子数组,因为任意子数组的异或值要么是 44,要么是 00。

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

首页