#P14626. [2018 KAIST RUN Fall] Fake Plastic Trees

    ID: 14493 Type: RemoteJudge 1000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>2018Special Judge高校校赛

[2018 KAIST RUN Fall] Fake Plastic Trees

题目描述

Tree\textbf{Tree} is a recursive structure, which is either:

  • Empty\textbf{Empty}. Empty tree is denoted as 1-1 and has a size of 0.
  • Non-empty\textbf{Non-empty}. Non-empty tree TT is denoted as a pair of two trees (T1,T2)(T_1, T_2), where T1T_1 is called left subtree\textbf{left subtree} of TT, and T2T_2 is called right subtree\textbf{right subtree} of TT. If T=(1,1)T = (-1, -1), then we call such TT a leaf\textbf{leaf}. Leaf has a size of 1, and non-leaf has a size of T1+T2|T_1| + |T_2|, where T1|T_1| is the size of T1T_1, and T2|T_2| is the size of T2T_2.

A non-empty tree TT is a Fake Plastic Tree\textbf{Fake Plastic Tree}, if the tree is balanced\textit{balanced}. Formally, Let T=(T1,T2)T = (T_1, T_2). If T1=T2|T_1| = |T_2| or T1=T2+1|T_1| = |T_2| + 1 holds, then TT 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\textit{null pointer} exists (which corresponds to empty tree, 1-1). You can allocate a tree in the memory, by setting T1T_1 and T2T_2 as either a null pointer or a pointer of an existing tree. Then, the memory is extended by adding T=(T1,T2)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 MM is an inductive structure, which at first contains only empty tree 1-1. (M={1}M = \{-1\}). You can expand the memory with following operation MM{(T1,T2)}M \leftarrow M \cup \{(T_1, T_2)\}, where T1M,T2MT_1 \in M, T_2 \in M. If a tree TT is inserted in ii-th stage, then it has the index\textbf{index} i1i-1. For a tree with index ii, their subtrees can be represented as a pair of integer in range [1,i1][-1, i-1].

Your task is to construct a memory MM, which satisfies the following:

  • Every tree in MM is either empty or Fake Plastic Tree.
  • MM has at most 125 non-empty trees.
  • There exists a tree TMT \in M, where T=N|T| = N holds. NN is an integer, and is given as an input.

输入格式

The first line contains a single integer TT, the number of test cases. (1T20001 \leq T \leq 2000)

In the next TT lines, a single integer NN is given, which indicates the number of leaves your tree should contain. (1N10181 \leq N \leq 10^{18})

输出格式

For each case, you should print V+2V + 2 lines, where VV is the number of non-empty trees in MM. (1V1251 \leq V \leq 125).

In the first line, you should print single integer VV.

In the next VV lines, you should print two space-separated integer Li,RiL_i, R_i, which indicates the index of left subtree and right subtree for a tree with index ii. (1Li,Rii1-1 \leq L_i, R_i \leq i - 1).

In the V+2V+2-th line, you should print PP, the index of the tree which contains NN nodes. (0PV10 \leq P \leq V-1).

It is guaranteed that an answer always exists under the given condition.

4
1
2
3
4
1
-1 -1
0
3
-1 -1
-1 -1
0 1
2
3
-1 -1
0 0
1 0
2
5
-1 -1
0 0
0 0
2 1
1 2
3

提示

:::align{center}

Illustration of output for N=4N = 4 in the example. :::