#P6241. [eJOI 2019] 塔

[eJOI 2019] 塔

Description

Jernej feels very bored at night, so he invents a game. He wants to use number cards to build a tower. At the beginning, he writes the number 11 on a card.

Jernej may write a new number on another card and place it on the top of the tower. This new number must be equal to the sum of the numbers in some consecutive segment of the current tower. In other words, suppose there are already nn numbers in the tower. You may choose any segment [l,u][l,u] in the tower, compute the sum of this segment, and add the resulting new number to the top of the tower, where 1lun1\le l\le u\le n.

Jernej wants to build TT towers (equivalently, multiple queries). The top number of each tower is one of TT (possibly different) target numbers he wants. You need to help him find the minimum number of steps to build these towers and output a corresponding plan.

Input Format

The first line contains an integer TT, the number of towers.

The next TT lines each contain an integer qq, meaning Jernej wants to build a tower whose top number is qq.

It is guaranteed that a solution exists.

Output Format

For each query qq:

  • Output one line containing an integer ss (0s1030\le s\le 10^3), the minimum number of steps.
  • Then output ss lines, each containing two integers l,ul,u separated by a space, describing the plan to build the tower (print earlier operations first).
3
2
3
7
2
1 1
1 2
3
1 1
2 2
1 3
4
1 1
1 2
2 3
1 4​

Hint

Special Judge Scoring Rules

This problem has 1010 test points. For each test point, the scoring rules are:

  • For any tower in the test point, if the minimum number of steps output by your program is exactly the same as the standard answer, then you will get 1010 points for this test point.
  • For any tower in the test point, if your program’s output is incorrect, you get 00 points (during judging, if the output is incomplete you may get UKE).
  • If your answer is not optimal but still correct, then for the ii-th tower in this test point, your score is $\text{score}_i =1+\dfrac{\text{minimum steps}}{\text{solution steps}}\times 7$, where minimum steps\text{minimum steps} is the minimum number of steps in the correct answer, and solution steps\text{solution steps} is the answer output by your program. The final score of this test point is mini[1,T]{scorei}\min\limits_{i\in [1,T]} \{\text{score}_i\}. Round up to two decimal places.

Sample Input/Output Explanation

Query 1 Explanation:

  • Jernej wants to build a tower with top number 22. Initially the tower is {1}\{1\} (the left side is the bottom and the right side is the top).
  • Step 1: choose segment [1,1][1,1], sum all elements in {1}\{1\} to get 11, now the tower is {1,1}\{1,1\}.
  • Step 2: choose segment [1,2][1,2], sum all elements in {1,1}\{1,1\} to get 22, now the tower is {1,1,2}\{1,1,2\}. The requirement of the query is now satisfied.

Query 2 Explanation:

  • There is more than one way to build a tower whose top is 33. Besides the one in the sample output, the following is also a correct answer:
1 1
1 2
2 3

Constraints

This problem uses bundled testdata and has 7 subtasks.

  • Subtask 1 (1 test case - 10 points): T10,q10T\le 10,q\le 10.
  • Subtask 2 (1 test case - 10 points): T20,q20T\le 20,q\le 20.
  • Subtask 3 (1 test case - 10 points): T=100,q100T= 100,q\le 100.
  • Subtask 4 (1 test case - 10 points): T=103,q104T= 10^3,q\le 10^4.
  • Subtask 5 (1 test case - 10 points): T=103,q105T= 10^3,q\le 10^5.
  • Subtask 6 (1 test case - 10 points): T=103,q106T= 10^3,q\le 10^6.
  • Subtask 7 (1 test case - 10 points): T=103,q109T= 10^3,q\le 10^9.
  • Subtask 8 (1 test case - 10 points): T=103,q1012T= 10^3,q\le 10^{12}.
  • Subtask 9 (2 test cases - 20 points): no additional constraints.

For all testdata, it is guaranteed that 1T103,1q10181\le T\le 10^3,1\le q\le 10^{18}.

Notes

The original problem is from: eJOI2019 Problem D. Tower.

Translation provided by: @_Wallace_.

Translated by ChatGPT 5