#703. 异或和

异或和

D 异或和

题目描述

给定一个长度为 nn 的非负整数数组 aa

你需要计算 $\sum_{l=1}^{n} \sum_{r=l}^{n} f(l, r) \cdot (r - l + 1)$ 的值,其中 f(l,r)f(l, r) 表示 $a_l \oplus a_{l+1} \oplus \dots \oplus a_{r-1} \oplus a_r$(符号 \oplus 表示按位异或运算)。

由于答案可能非常大,请输出其对 998244353998244353 取模后的结果。

输入格式

第一行包含一个整数 nn1n31051 \le n \le 3 \cdot 10^5),表示数组 aa 的长度。

第二行包含 nn 个整数 a1,a2,,ana_1, a_2, \dots, a_n0ai1090 \le a_i \le 10^9)。

输出格式

输出一个整数,表示 $\sum_{l=1}^{n} \sum_{r=l}^{n} f(l, r) \cdot (r - l + 1)$ 对 998244353998244353 取模后的值。

输入输出样例

3
1 3 2
12
4
39 68 31 80
1337
7
313539461 779847196 221612534 488613315 633203958 394620685 761188160
257421502

说明/提示

在第一个样例中,答案等于 $f(1, 1) + 2 \cdot f(1, 2) + 3 \cdot f(1, 3) + f(2, 2) + 2 \cdot f(2, 3) + f(3, 3) = 1 + 2 \cdot 2 + 3 \cdot 0 + 3 + 2 \cdot 1 + 2 = 12$。

数据范围

对于20%20\%样例 n<=1000n<=1000

对于另外20%20\%样例 ai<=1a_i<=1

对于100%100\%样例 n<=3105,ai<=109n<=3*10^5,a_i<=10^9