Under construction

Still being built. Things may change

Tree Visits

Time limit5sMemory limit1536 MB

Summary
Maintain a value X under increments of 2^C modulo 2^N, mark all nodes on each root-to-leaf walk, and report the count of distinct visited nodes.
Level

Medium7 of 10

Topics
Tree, Bit manipulation, Prefix sum, Implementation
Solved
No attempts yet

Problem

There is a perfect binary tree of height NN. It has 2N+1−12^{N+1}-1 nodes in total, and 2N2^N of them are leaves at depth NN.

You walk down the tree using an NN-bit binary number XX. Read the bits of XX starting from the leftmost one: a 0 takes you to the left child, a 1 takes you to the right child. For example, when N=2N = 2, X=0=002X = 0 = 00_2 takes you to the leftmost leaf, and X=3=112X = 3 = 11_2 takes you to the rightmost leaf. With X=2=102X = 2 = 10_2 you move from the root to its right child, then to that child's left child.

At the very beginning X=0X = 0 and only the root has been visited. Write a program that processes the following two queries.

  • 1 C: change XX to (X+2C) mod 2N(X + 2^C) \bmod 2^N. Then walk down from the root using the new XX and visit every node you pass. The root and the leaf you land on both count as visited nodes.
  • 2: print how many distinct nodes have been visited so far. A node visited several times is counted once.

Input

The first line contains the height NN of the tree and the number of queries QQ. (1≤N,Q≤1051 \le N, Q \le 10^5)

Each of the next QQ lines contains one query. A query of the first kind has the form 1 C with 0≤C<N0 \le C < N. A query of the second kind is the single character 2, and at least one such query is given.

Output

For each query of the second kind, print the number of distinct visited nodes on its own line.

Examples2

  1. Example 1

    Input
    2 9
    1 0
    2
    1 1
    2
    1 0
    2
    1 0
    1 0
    2
    
    Expected output
    3
    5
    6
    7
    
  2. Example 2

    Input
    1 5
    2
    1 0
    2
    1 0
    2
    
    Expected output
    1
    2
    3