Subtree MEX

You will be given a balanced binary tree of NNN nodes. Each of the nodes of the tree will contain a non-negative integer value. Then, you will be asked to perform QQQ queries on the given tree. Each of the queries will be one of the two types described below.

This is a companion discussion topic for the original entry at