서브트리를 재사용해 125개 이하의 균형 이진 트리를 만들고, 노드가 정확히 N개인 트리 하나를 포함하는 구성을 출력합니다.
어려움8트리수학그리디구현아직 제출이 없습니다시간 제한1초메모리 제한1024 MBTree is a recursive structure, which is either:
A non-empty tree T is a Fake Plastic Tree, if the tree is balanced. Formally, Let T=(T_1, T_2). If ∣T_1∣=∣T_2∣ or ∣T_1∣=∣T_2∣+1 holds, then T is a Fake Plastic Tree.
In computer science, trees are commonly used as a data structure, and they are stored in a memory. At first, there are no trees in the memory, and only an imaginary null pointer exists (which corresponds to empty tree, −1). You can allocate a tree in the memory, by setting T_1 and T_2 as either a null pointer or a pointer of an existing tree. Then, the memory is extended by adding T=(T_1, T_2) into its structure. Note that pointer can be described as a small integer, reducing the need for explicitly storing the whole tree.
Formally, memory M is an inductive structure, which at first contains only empty tree −1. (M=−1). You can expand the memory with following operation M←M∪(T_1, T_2), where T_1∈M, T_2∈M. If a tree T is inserted in i-th stage, then it has the index i−1. For a tree with index i, their subtrees can be represented as a pair of integer in range \[−1, i−1].
Your task is to construct a memory M, which satisfies the following:
The first line contains a single integer T, the number of test cases. (1≤T≤2,000)
In the next T lines, a single integer N is given, which indicates the number of leaves your tree should contain. (1≤N≤1018)
For each case, you should print V+2 lines, where V is the number of non-empty trees in M. (1≤V≤125).
In the first line, you should print single integer V.
In the next V lines, you should print two space-separated integer L_i, R_i, which indicates the index of left subtree and right subtree for a tree with index i. (−1≤L_i, R_i≤i−1).
In the (V+2)-th line, you should print P, the index of the tree which contains N nodes. (0≤P≤V−1).
It is guaranteed that an answer always exists under the given condition.