luogu#P5390. [Cnoi2019] 数学作业

[Cnoi2019] 数学作业

Background

Gensokyo, the Spring Festival, and lights in every home.

Teacher Kamishirasawa Keine would of course not miss such a good chance... and assigned homework.

Problem Description

Now Cirno has homework for TT days. The homework for each day can be represented by an ordered pair (n,V)(n, V), where nn is the size of the set, and VV is a set of size nn. Now Cirno needs to compute the sum of the XOR values over all subsets of VV. The answer should be taken modulo 998244353998\,244\,353.

Formally:

$$\text{ans}\equiv \sum_{S \subseteq V} \mathop{\bigoplus}\limits_{ s \in S } s \pmod {998\,244\,353}$$

Input Format

The first line contains an integer TT.

The following TT lines each contain an ordered pair (n,V)(n, V).

Output Format

Output TT lines, each containing one integer representing the answer.

1
3 1 2 3
12

Hint

  • Subtask 1 (17 pts): T,n8T, n \le 8.
  • Subtask 2 (22 pts): T,n100T, n \le 100.
  • Subtask 3 (61 pts): T,n3×106T, n \le 3\times 10^6.

For 100%100\% of the testdata, V3×106,0p109\sum |V| \le 3 \times 10^6, 0 \le p \le 10^9.

Translated by ChatGPT 5