#P13308. 故障

    ID: 11574 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>树形数据结构并查集洛谷原创O2优化进制字典树 Trie洛谷月赛哈希表

故障

Description

Yuki has a full binary tree with nn levels. The nodes are numbered according to a level-order traversal (see explanation).

This tree undergoes mm operations.

  1. The tree experiences a fault. The edge between node uu and its parent is deleted. If the node is the root or this edge has already been deleted, nothing happens.

  2. Query the size of the connected component containing node uu.

Input Format

The first line contains two integers nn and mm.

The next mm lines each contain two integers oo and uu.

If o=1o=1, perform operation 1 on uu. If o=2o=2, perform operation 2 on uu.

Output Format

To simplify the output, you only need to print one line, representing the XOR of all answers for each query.

5 3
2 3
1 3
2 3

16

5 3
1 2
1 3
2 1
1

Hint

  1. A full binary tree with nn levels refers to a full binary tree with a maximum depth of nn, where the root node has a depth of 1.
  2. If node ii has children, the level-order traversal numbering of the full binary tree satisfies that the left child of ii is 2i2i and the right child is 2i+12i+1.

Explanation for Sample 1

For the first query, before deleting the edge between 3 and 1, the answer is the size of the entire tree, which is 31. After deletion, it becomes the size of 3's subtree, which is 15. The XOR sum is 3115=1631\oplus 15=16.

Data Range

There are 10 test cases.

For the first 20% of the data, n10,m103n \leq 10, m \leq 10^3.

For the first 50% of the data, n20,m104n \leq 20, m \leq 10^4.

For the first 80% of the data, n30n \leq 30.

For all data, $2 \leq n \leq 60, 1 \leq m \leq 3 \times 10^5, 1 \leq o \leq 2, 1 \leq u \leq 2^n -1$.