1109A.md (2010B)
1 Source: https://codeforces.com/problemset/problem/1109/A 2 3 A. Sasha and a Bit of Relax 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful. 22 23 Therefore, Sasha decided to upsolve the following problem: 24 25 You have an array $a$ with $n$ integers. You need to count the number of funny pairs $(l, r)$ $(l \leq r)$. To check if a pair $(l, r)$ is a funny pair, take $mid = \frac{l + r - 1}{2}$, then if $r - l + 1$ is an even number and $a_l \oplus a_{l+1} \oplus \ldots \oplus a_{mid} = a_{mid + 1} \oplus a_{mid + 2} \oplus \ldots \oplus a_r$, then the pair is funny. In other words, $\oplus$ of elements of the left half of the subarray from $l$ to $r$ should be equal to $\oplus$ of elements of the right half. Note that $\oplus$ denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). 26 27 It is time to continue solving the contest, so Sasha asked you to solve this task. 28 29 Input 30 31 The first line contains one integer $n$ ($2 \le n \le 3 \cdot 10^5$) — the size of the array. 32 33 The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \lt 2^{20}$) — array itself. 34 35 Output 36 37 Print one integer — the number of funny pairs. You should consider only pairs where $r - l + 1$ is even number. 38 39 Examples 40 41 Input 42 43 ``` 44 5 45 1 2 3 4 5 46 ``` 47 48 Output 49 50 ``` 51 1 52 ``` 53 54 Input 55 56 ``` 57 6 58 3 2 2 3 7 6 59 ``` 60 61 Output 62 63 ``` 64 3 65 ``` 66 67 Input 68 69 ``` 70 3 71 42 4 2 72 ``` 73 74 Output 75 76 ``` 77 0 78 ``` 79 80 Note 81 82 Be as cool as Sasha, upsolve problems! 83 84 In the first example, the only funny pair is $(2, 5)$, as $2 \oplus 3 = 4 \oplus 5 = 1$. 85 86 In the second example, funny pairs are $(2, 3)$, $(1, 4)$, and $(3, 6)$. 87 88 In the third example, there are no funny pairs.