#P9619. 生成树

生成树

Background

We are immature fighters, and we will never admit defeat now.

We are immature dreamers, and we will never cry now.

Problem Description

You are given an undirected complete graph G(V,E)G(V,E) and a weight array aa of length V|V|. aia_i represents the weight of the node with index ii.

Define the edge value of an edge e(u,v)e(u,v) as val(e)val(e), where val(e)=auavval(e)=a_u\oplus a_v, i.e., the bitwise XOR of the weights of the two endpoints. Define the weight of a spanning tree T(V,Et)T(V,E_t) of GG as Val(T)Val(T), where Val(T)=eEtval(e)Val(T)=\sum_{e\in E_t}val(e), i.e., the sum of edge values on the tree.

You need to compute TVal(T)\sum_{T}Val(T), i.e., the sum of the weights of all different spanning trees in GG.

We consider two spanning trees to be different if and only if their edge sets EtE_t are not exactly the same, i.e., there exists at least one edge that belongs to exactly one of the two spanning trees.

Input Format

There are two lines.

The first line contains an integer nn, denoting V|V|, i.e., the number of nodes.

The second line contains nn integers, which are a1ana_1\sim a_n in order.

Output Format

Output one integer in one line, which is your answer modulo 998244353998244353.

3
1 2 3
12
6
1 1 4 5 1 4
19008
10
1 1 4 5 1 4 1 9 1 9
567022588

Hint

Sample #1 Explanation:

Consider that there are three spanning trees in total: {123},{132},{312}\{1-2-3\},\{1-3-2\},\{3-1-2\}.

Their weights are (12)+(23)=4(1\oplus 2)+(2\oplus 3)=4, (13)+(32)=3(1\oplus 3)+(3\oplus 2)=3, and (31)+(12)=5(3\oplus 1)+(1\oplus 2)=5.

So 4+3+5=124+3+5=12.

Constraints

It is guaranteed that for all testdata, 1n1061\le n\le 10^6, 0ai1090\le a_i\le 10^9. |Test Point ID|Constraints|Special Property| |:-:|:-:|:-:| |11||All aia_i are equal.| |252\sim 5|n4n\le 4|| |6106\sim 10|n300n\le 300|| |111211\sim 12|n5×104n\le 5\times 10^4|ai=[i=1]a_i=[i=1]| |111511\sim 15|n5×104n\le 5\times 10^4|| |162016\sim 20|||

Translated by ChatGPT 5