#arc151d. [arc151_d]Binary Representations and Queries

[arc151_d]Binary Representations and Queries

Problem Statement

You are given an integer sequence A=(A0,A1,ldots,A2N1)A = (A_0, A_1, \\ldots, A_{2^N-1}) of length 2N2^N.

Additionally, QQ queries are given. For each i=1,2,ldots,Qi = 1, 2, \\ldots, Q, the ii-th query is represented by two integers XiX_i and YiY_i and asks you to perform the operation below.

For each j=0,1,2,ldots,2N1j = 0, 1, 2, \\ldots, 2^N-1 in this order, do the following.

  1. First, let bN1bN2ldotsb0b_{N-1}b_{N-2}\\ldots b_0 be the binary representation of jj with NN digits. Additionally, let jj' be the integer represented by the binary representation bN1bN2ldotsb0b_{N-1}b_{N-2}\\ldots b_0 after flipping the bit bXib_{X_i} (changing 00 to 11 and 11 to 00).
  2. Then, if bXi=Yib_{X_i} = Y_i, add the value of AjA_j to AjA_{j'}.

Print each element of AA, modulo 998244353998244353, after processing all the queries in the order they are given in the input.

What is binary representation with NN digits?

The binary representation of an non-negative integer XX (0leqX<2N0 \\leq X < 2^N) with NN digits is the unique sequence bN1bN2ldotsb0b_{N-1}b_{N-2}\\ldots b_0 of length NN consisting of 00 and 11 that satisfies:

  • sumi=0N1bicdot2i=X\\sum_{i = 0}^{N-1} b_i \\cdot 2^i = X.

Constraints

  • 1leqNleq181 \\leq N \\leq 18
  • 1leqQleq2times1051 \\leq Q \\leq 2 \\times 10^5
  • 0leqAilt9982443530 \\leq A_i \\lt 998244353
  • 0leqXileqN10 \\leq X_i \\leq N-1
  • Yiinlbrace0,1rbraceY_i \\in \\lbrace 0, 1\\rbrace
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN QQ A0A_0 A1A_1 ldots\\ldots A2N1A_{2^N-1} X1X_1 Y1Y_1 X2X_2 Y2Y_2 vdots\\vdots XQX_Q YQY_Q

Output

For each i=0,1,ldots,2N1i = 0, 1, \\ldots, 2^N-1, print the remainder AiA'_i when dividing AiA_i after processing all the queries by 998244353998244353, separated by spaces, in the following format:

A0A'_0 A1A'_1 ldots\\ldots A2N1A'_{2^N-1}


Sample Input 1

2 2
0 1 2 3
1 1
0 0

Sample Output 1

2 6 2 5

The first query asks you to do the following.

  • For j=0j = 0, we have b1b0=00b_1b_0 = 00 and j=2j' = 2. Since b1neq1b_1 \\neq 1, skip the addition.
  • For j=1j = 1, we have b1b0=01b_1b_0 = 01 and j=3j' = 3. Since b1neq1b_1 \\neq 1, skip the addition.
  • For j=2j = 2, we have b1b0=10b_1b_0 = 10 and j=0j' = 0. Since b1=1b_1 = 1, add the value of A2A_2 to A0A_0. Now we have A=(2,1,2,3)A = (2, 1, 2, 3).
  • For j=3j = 3, we have b1b0=11b_1b_0 = 11 and j=1j' = 1. Since b1=1b_1 = 1, add the value of A3A_3 to A1A_1. Now we have A=(2,4,2,3)A = (2, 4, 2, 3).

The second query asks you to do the following.

  • For j=0j = 0, we have b1b0=00b_1b_0 = 00 and j=1j' = 1. Since b0=0b_0 = 0, add the value of A0A_0 to A1A_1. Now we have A=(2,6,2,3)A = (2, 6, 2, 3).
  • For j=1j = 1, we have b1b0=01b_1b_0 = 01 and j=0j' = 0. Since b0neq0b_0 \\neq 0, skip the addition.
  • For j=2j = 2, we have b1b0=10b_1b_0 = 10 and j=3j' = 3. Since b0=0b_0 = 0, add the value of A2A_2 to A3A_3. Now we have A=(2,6,2,5)A = (2, 6, 2, 5).
  • For j=3j = 3, we have b1b0=11b_1b_0 = 11 and j=2j' = 2. Since b0neq0b_0 \\neq 0, skip the addition.

Thus, AA will be (2,6,2,5)(2, 6, 2, 5) after processing all the queries.


Sample Input 2

3 10
606248357 338306877 919152167 981537317 808873985 845549408 680941783 921035119
1 1
0 0
0 0
0 0
0 1
0 1
0 1
2 0
2 0
2 0

Sample Output 2

246895115 904824001 157201385 744260759 973709546 964549010 61683812 205420980