#P7442. 「EZEC-7」维护序列

「EZEC-7」维护序列

Description

You need to maintain a sequence.

At the beginning, the sequence has 2n2^n numbers, indexed starting from 00. The initial value of the ii-th number is ii. You need to support the following three operations:

  • Define aa as the subsequence consisting of all elements whose indices are even, and define bb as the subsequence consisting of all elements whose indices are odd. Concatenate aa and bb to form a new sequence.
  • Define aa as the subsequence consisting of all elements whose indices are odd, and define bb as the subsequence consisting of all elements whose indices are even. Concatenate aa and bb to form a new sequence.
  • Query the number at index xx.

In total, there will be mm operations.

Input Format

The first line contains two positive integers n,mn,m.

Then there are mm lines. Each line contains two non-negative integers op,xop,x, representing one operation.

If op=1op=1, then if x=0x=0 it means the first operation, and if x=1x=1 it means the second operation.

If op=2op=2, it means the third operation, and the parameter xx is the queried index xx.

Output Format

For each op=2op=2, output one line, which is the corresponding number.

2 7
2 0
1 0
2 1
1 1
2 2
1 0
2 3
0
2
0
1

Hint

Sample Explanation

The sequence from left to right before and after all operations is as follows:

{0,1,2,3}\{0,1,2,3\}

The number at index 00 is 00.

{0,2},{1,3}\{0,2\},\{1,3\} {0,2,1,3}\{0,2,1,3\}

The number at index 11 is 22.

{2,3},{0,1}\{2,3\},\{0,1\} {2,3,0,1}\{2,3,0,1\}

The number at index 22 is 00.

{2,0},{3,1}\{2,0\},\{3,1\} {2,0,3,1}\{2,0,3,1\}

The number at index 33 is 11.

Constraints

This problem uses bundled testdata.

  • Subtask 1 (10 points): There is no operation with op=1op=1.
  • Subtask 2 (10 points): n10m103n\leq 10,m\leq 10^3.
  • Subtask 3 (20 points): n10n\leq 10.
  • Subtask 4 (20 points): m103m\leq 10^3.
  • Subtask 5 (20 points): For operations with op=1op=1, x=0x=0.
  • Subtask 6 (20 points): No special restrictions.

For 100%100\% of the data, 1n321\leq n\leq 321m1061\leq m\leq 10^6.

If op=1op=1, then x{0,1}x\in\{0,1\}. If op=2op=2, then 0x<2n0\leq x<2^n.

Translated by ChatGPT 5