#P98. [NOI 2025 Day 2] 集合

[NOI 2025 Day 2] 集合

Person in Charge

Problem Description

Little X has 2n2^n numbers labeled from 00 to 2n12^n - 1, where the ii-th (0i<2n0 \le i < 2^n) number is aia_i.

For a subset S{0,1,,2n1}S \subseteq \{0, 1, \ldots, 2^n - 1\}, define f(S)f(S) as the bitwise AND of all numbers in SS. Specifically, if SS is empty, then f(S)=2n1f(S) = 2^n - 1.

Define an ordered pair (P,Q)(P, Q) of subsets P,QP, Q of {0,1,,2n1}\{0, 1, \ldots, 2^n - 1\} (which can be empty) as special if and only if PQ=P \cap Q = \varnothing and f(P)=f(Q)f(P) = f(Q). The weight of the ordered pair (P,Q)(P, Q) is defined as the product of all numbers whose labels are included in PQP \cup Q, i.e., iPQai\prod_{i \in P \cup Q} a_i. Specifically, if PQ=P \cup Q = \varnothing, the weight of (P,Q)(P, Q) is 11.

Little X wants to know the sum of the weights of all special ordered pairs. Please help him compute this value. Since the answer may be large, you only need to output the result modulo 998,244,353998,244,353.

Input Format

This problem contains multiple test cases.

The first line of input contains two non-negative integers c,tc, t, representing the test case ID and the number of test cases, respectively. c=0c = 0 indicates that the test case is a sample.

For each test case:

  • The first line contains a positive integer nn, indicating there are 2n2^n numbers.
  • The second line contains 2n2^n non-negative integers a0,,a2n1a_0, \ldots, a_{2^n - 1}.

Output Format

For each test case, output one line containing an integer, representing the sum of the weights of all special ordered pairs modulo 998,244,353998,244,353.

Samples

0 2
2
1 2 3 4
3
1 1 1 1 1 1 1 1
117
2091

Sample 2

See set/set2.in and set/set2.ans in the contestant directory.

This sample satisfies the constraints of Test Case 2.

Sample 3

See set/set3.in and set/set3.ans in the contestant directory.

This sample satisfies the constraints of Test Case 3.

Sample 4

See set/set4.in and set/set4.ans in the contestant directory.

This sample satisfies the constraints of Test Case 9.

Data Range

For all test data, the following guarantees hold:

  • 1t31 \le t \le 3;
  • 2n202 \le n \le 20;
  • For all 0i<2n0 \le i < 2^n, 0ai<998,244,3530 \le a_i < 998,244,353.
Test Case ID nn \le Special Properties
11 44 B
22 None
33 88 B
44 None
55 1010 B
66 None
7,87, 8 1212 B
99 None
101210 \sim 12 1616 B
13,1413, 14 None
15,1615, 16 2020 AB
17,1817, 18 A
192119 \sim 21 B
222522 \sim 25 None
  • Special Property A: At most 2424 indices ii satisfy ai0a_i \neq 0.
  • Special Property B: For all 0i<2n0 \le i < 2^n, ai998,244,352a_i \neq 998,244,352.