#P16603. [SYSUCPC 2025] Gray Transform (Weakened)

[SYSUCPC 2025] Gray Transform (Weakened)

Problem Description

Gray code is a binary numeral system where two successive values differ in only one bit. This property makes it useful in various applications, such as minimizing errors in digital communication and measurement systems. Gray code is also known for its reflective and cyclic characteristics, which help eliminate significant errors during random sampling. It was invented by Frank Gray in the 1940s and has various construction methods.

An nn-bit Gray code Gn=[Gn,0,Gn,1,,Gn,2n1]G_n=[G_{n,0},G_{n,1},\cdots,G_{n,2^n-1}] can be generated by the following algorithm:

  • The 11-bit Gray code consists of the two binary numbers 00 and 11. That is, G1=[0,1]G_1=[0,1].
  • The first 2n2^n binary numbers of the (n+1)(n+1)-bit Gray code are the same as the nn-bit Gray code; the last 2n2^n binary strings of the (n+1)(n+1)-bit Gray code are formed by taking the nn-bit Gray code, arranging it in reverse order\textbf{reverse order}, and then adding 2n2^n to each number. That is, $G_{n+1}=[G_{n,0},G_{n,1},\cdots,G_{n,2^n-1},G_{n,2^n-1}+2^n,G_{n,2^n-2}+2^n,\cdots,G_{n,0}+2^n]$.

For example, G2=[0,1,3,2]G_2=[0,1,3,2], G3=[0,1,3,2,6,7,5,4]G_3=[0,1,3,2,6,7,5,4].

Now there is an array a0,a1,,a2n1a_0,a_1,\cdots,a_{2^n-1} of length 2n2^n. Initially, for all i{0,1,,2n1}i\in\{0,1,\cdots,2^n-1\}, ai=ia_i=i. We will perform qq operations on this array, where each operation is one of the following two types:

  • Given mm and k1,k2,,kmk_1,k_2,\cdots,k_m, for i=1,2,,mi=1,2,\cdots,m in increasing order, for every j{0,1,,2ki1}j\in\{0,1,\cdots,2^{k_i}-1\}, if aj<2kia_j<2^{k_i}, then set aj=Gki,aja_j=G_{k_i,a_j}; otherwise, do nothing to aja_j.
  • Given pp, query the value of apa_p.

Please output the results of each query in order.

Input Format

The first line of input contains two integers, which are nn (1n101\le n\le 10) and qq (1q50001\le q\le 5000).

The next qq lines describe the operations. Each of these lines starts with an integer op\text{op} (op{1,2}\text{op}\in\{1,2\}), indicating the type of operation.

  • If op=1\text{op}=1, then the line is followed by an integer mm (1m50001\le m\le 5000) and mm integers k1,k2,,kmk_1,k_2,\cdots,k_m (1kin1\le k_i\le n for all i{1,2,,m}i\in\{1,2,\cdots,m\}), representing a type-1 operation.
  • If op=2\text{op}=2, then the line is followed by the binary form\textbf{binary form} of an integer pp (0p<2n0\le p< 2^n) without leading zeros, representing a type-2 operation with parameter pp.

It is guaranteed that the sum of mm over all type-1 operations does not exceed 50005000.

Output Format

Output the binary forms\textbf{binary forms} of all the results of the type-2 operations without leading zeros, each on its own line.

3 4
2 0
1 4 1 2 3 2
2 100
2 10
0
110
11

Hint

Initially, [a0,a1,,a2n1]=[0,1,2,3,4,5,6,7][a_0,a_1,\cdots,a_{2^n-1}]=[0,1,2,3,4,5,6,7].

After the second operation, [a0,a1,,a2n1]=[0,1,3,2,6,7,5,4][a_0,a_1,\cdots,a_{2^n-1}]=[0,1,3,2,6,7,5,4].