Codeforces Round 940 (Div. 2) and CodeCraft-23
D
A BIT of an Inequality
Codeforces
1900
原题
← CE →
翻译中…

You are given an array $a_1, a_2, \ldots, a_n$. Find the number of tuples ($x, y, z$) such that:

翻译中…
  • $1 \leq x \leq y \leq z \leq n$, and
  • $f(x, y) \oplus f(y, z) \gt f(x, z)$.
翻译中…

We define $f(l, r) = a_l \oplus a_{l + 1} \oplus \ldots \oplus a_{r}$, where $\oplus$ denotes the bitwise XOR operation.

翻译中…

Input

翻译中…

The first line contains a single integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases.

翻译中…

The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$).

翻译中…

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$).

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.

翻译中…

Output

翻译中…

For each test case, output a single integer on a new line — the number of described tuples.

翻译中…

Note

翻译中…

In the first case, there are 4 such tuples in the array $[6, 2, 4]$:

翻译中…
  • ($1$, $2$, $2$): $(a_1 \oplus a_2) \oplus (a_2) = 4 \oplus 2 \gt (a_1 \oplus a_2) = 4$
  • ($1$, $1$, $3$): $(a_1) \oplus (a_1 \oplus a_2 \oplus a_3) = 6 \oplus 0 \gt (a_1 \oplus a_2 \oplus a_3) = 0$
  • ($1$, $2$, $3$): $(a_1 \oplus a_2) \oplus (a_2 \oplus a_3) = 4 \oplus 6 \gt (a_1 \oplus a_2 \oplus a_3) = 0$
  • ($1$, $3$, $3$): $(a_1 \oplus a_2 \oplus a_3) \oplus (a_3) = 0 \oplus 4 \gt (a_1 \oplus a_2 \oplus a_3) = 0$
翻译中…

In the second test case, there are no such tuples.

翻译中…

样例

Input #1
3
3
6 2 4
1
3
5
7 3 7 2 1
Output #1
4
0
16
InputCopy OutputCopy
题目信息
题号
1957D
时间限制
2 s
内存限制
256 MB
标签
位运算
暴力
动态规划
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。