#P9162. variance
variance
Problem Description
Given a sequence , define $f(l,r)=(a_l\oplus a_{l+1}\oplus \cdots \oplus a_r)+(a_l\vee a_{l+1}\vee \cdots \vee a_r)$, where denotes the bitwise XOR operation, and denotes the bitwise OR operation.
You need to compute the variance of all values that satisfy . To avoid precision errors, and since the answer may be very large, output $(v\times \frac{n^2\times (n+1)^2}{4}) \kern{3pt}\mathrm {mod}\kern{3pt} 998244353$.
Note: Do not take modulo during the computation. Only take modulo for the final result.
Input Format
The first line contains a positive integer .
The second line contains positive integers .
Output Format
Output an integer $(v\times \frac{n^2\times (n+1)^2}{4}) \kern{3pt}\mathrm {mod}\kern{3pt} 998244353$.
3
2 1 3
80
4
4 1 3 2
1244
5
1 2 3 2 1
444
Hint
Definition of variance: for numbers , their variance is:
where is the average of , that is, $\dfrac {1} {n} \displaystyle\sum\limits_{i=1}^n a_i$.
For of the testdata, .
For of the testdata, .
For another of the testdata, .
For of the testdata, .
Translated by ChatGPT 5