Kia、Kio 与生命之树AI (CI翻译)
After unlocking the crystal terminal, Kia and Kio discovered the blueprint for the kingdom's forgotten heart: a digital Tree of Life, seeded by the array $a_1, a_2, \ldots, a_n$.
解锁水晶终端后,Kia 和 Kio 发现了王国被遗忘的核心蓝图:一棵由数组 $a_1, a_2, \ldots, a_n$ 播种而成的数字生命之树。AI (CI翻译)
To restore its pulse, they had to weave every possible incarnation of the Tree together. For any continuous segment, Kia would gently select an index $i$ to plant the root. Trusting her vision, Kio would carefully weave the branches of life — crafting the left subtree from the preceding segment $[1, i-1]$ and the right subtree from the succeeding segment $[i+1, n]$.
为了让它重新焕发生机,他们必须将这棵树所有可能的形态编织在一起。对于任意一个连续区间,Kia 会轻轻选取一个下标 $i$ 来种下树根。Kio 信任她的眼光,仔细编织生命的枝干——用前面的区间 $[1, i-1]$ 构造左子树,用后面的区间 $[i+1, n]$ 构造右子树。AI (CI翻译)
Once a Tree of Life bloomed, its vital resonance, $f(\text{tree})$, was defined by its bonds. If one were to sever any of the $n-1$ delicate branches, the Tree would split into two disconnected halves, releasing an energy of $X+Y$, where $X$ and $Y$ are the bitwise XOR sums of the array elements remaining in the first and second halves, respectively.
每当一棵生命之树长成,它的生命共鸣值 $f(\text{tree})$ 由树枝决定。若剪断 $n-1$ 条纤细树枝中的任意一条,整棵树就会分成两个不相连的部分,并释放出 $X+Y$ 的能量。其中,$X$ 和 $Y$ 分别是剩余数组元素在这两个部分中的按位异或和。AI (CI翻译)
The total power of the Tree, $f(\text{tree})$, is the sum of these released energies across all $n-1$ branches.
这棵树的总能量 $f(\text{tree})$,就是剪断每一条树枝所释放能量的总和。AI (CI翻译)
Kia wanted to know the ultimate vital force they could awaken. Help them compute the total sum of $f(\text{tree})$ across every valid Tree of Life born from their shared bond, modulo $998\,244\,353$.
Kia 想知道他们能够唤醒的终极生命之力。请帮助他们计算所有可能的生命之树的 $f(\text{tree})$ 之和,并对 $998\,244\,353$ 取模。AI (CI翻译)
Input
输入格式
AI (CI翻译)Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
每个测试包含多组测试用例。第一行包含测试用例数量 $t$($1 \le t \le 10^4$)。接下来是各测试用例的描述。AI (CI翻译)
The first line of each test case contains a single integer $n$ ($1 \le n \le 2\cdot10^5$) — the size of the array.
每个测试用例的第一行包含一个整数 $n$($1 \le n \le 2\cdot10^5$),表示数组的大小。AI (CI翻译)
The second line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0 \le a_i \lt 2^{18}$).
第二行包含 $n$ 个整数 $a_1,a_2,\ldots,a_n$($0 \le a_i \lt 2^{18}$)。AI (CI翻译)
It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot10^5$.
保证所有测试用例的 $n$ 之和不超过 $2\cdot10^5$。AI (CI翻译)
Output
输出格式
AI (CI翻译)For each test case, print a single integer — the total sum of $f(\text{tree})$ across all valid Trees of Life, modulo $998\,244\,353$.
对于每个测试用例,输出一个整数——所有可能的生命之树的 $f(\text{tree})$ 之和,对 $998\,244\,353$ 取模。AI (CI翻译)
Note
说明
AI (CI翻译)For the first test case, $n=2$ and $a = [1,2]$. There are two valid trees that can be constructed: one with $a_1$ as the root and $a_2$ as the right child, and one with $a_2$ as the root and $a_1$ as the left child.
对于第一个测试用例,$n=2$ 且 $a = [1,2]$。可以构造两棵有效的树:一棵以 $a_1$ 为根、$a_2$ 为右孩子;另一棵以 $a_2$ 为根、$a_1$ 为左孩子。AI (CI翻译)
In both trees, severing the single branch leaves two components with XOR sums $X=1$ and $Y=2$. Thus, the value for each tree becomes $1 + 2 = 3$. The total energy accumulated across both Trees of Life is $3+3=6$.
在这两棵树中,剪断唯一的一条树枝后,两个部分的异或和均为 $X=1$ 和 $Y=2$。因此,每棵树的值都是 $1 + 2 = 3$。两棵生命之树的总能量为 $3+3=6$。AI (CI翻译)
For the second test case, $n=3$ and $a = [1,1,1]$.
对于第二个测试用例,$n=3$ 且 $a = [1,1,1]$。AI (CI翻译)
There are $5$ valid trees that can be constructed:
可以构造 $5$ 棵有效的树:AI (CI翻译)
- Root is
$1$:$\{(1,2), (2,3)\}$,$\{(1, 3), (2, 3)\}$; - Root is
$2$:$\{(1,2), (2,3)\}$; - Root is
$3$:$\{(1,3), (1,2)\}$,$\{(2, 3), (1, 2)\}$.
- 根为
$1$:${(1,2), (2,3)}$,${(1, 3), (2, 3)}$; - 根为
$2$:${(1,2), (2,3)}$; - 根为
$3$:${(1,3), (1,2)}$,${(2, 3), (1, 2)}$。
All trees are just a path with three vertices, and severing a single branch leaves two components with XOR sums $X=1$ and $Y=0$. So the value for each tree becomes $2$. The total energy accumulated across all five Trees of Life is $5\cdot 2=10$.
所有树都是由三个顶点组成的路径。剪断一条树枝后,两个部分的异或和为 $X=1$ 和 $Y=0$。因此,每棵树的值都是 $2$。五棵生命之树的总能量为 $5\cdot 2=10$。AI (CI翻译)
样例
5
2
1 2
3
1 1 1
3
1 2 3
4
2 1 4 7
5
5 12 9 14 1
6
10
40
318
2520
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。