#P10402. 「XSOI-R1」凑点

    ID: 11693 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>数学二分洛谷原创Special JudgeO2优化构造

「XSOI-R1」凑点

Problem Description

Little T will give you an integer sequence of length nn. You have a number xx in your hand, initially 00. You can perform the following operations so that, in the end, the difference between xx and cc is less than 10410^{-4}.

You may perform at most kk operations on xx:

  • add i: add aia_i to the counter xx, and then aia_i cannot be used in any operation anymore.

  • sub i: subtract aia_i from the counter xx, and then aia_i cannot be used in any operation anymore.

  • mul i: multiply the counter xx by aia_i, and then aia_i cannot be used in any operation anymore.

  • sqrt i: set aia_i to ai\sqrt {a_i}. Each aia_i can be square-rooted at most once.

  • pow f: change the counter xx into xfx^f, where ff can be a floating-point number.

All aia_i must be used exactly once in an addition, subtraction, or multiplication operation on xx.

During the computation, the values of aia_i and xx must not exceed 101010^{10}. The problem guarantees that a solution exists. If there are multiple solutions, output any one of them.

This problem requires high precision. Please improve the precision of your algorithm.

Constraints

This problem uses bundled testdata.

  • Subtask 0 (10 pts): n5n \leq 5, k=n2k = n^2. It is guaranteed that a solution can be obtained using only addition and subtraction.

  • Subtask 1 (20 pts): n5n \leq 5, k=n2k = n^2. It is guaranteed that a solution can be obtained using addition, subtraction, multiplication, and square root.

  • Subtask 2 (15 pts): n10n \leq 10, ai2a_i \leq 2, k=n+1k = n + 1.

  • Subtask 3 (55 pts): k=n+1k = n + 1.

For all testdata: 0n1050 \leq n \leq 10^{5}, i=1nai1010\sum_{i=1}^{n}{a_i} \le 10^{10}, 0c10100 \leq c \leq 10^{10}.

Input Format

The first line contains three integers nn, kk, cc.

The second line contains nn integers, representing the sequence aa.

Output Format

The first line contains an integer gg, the total number of operations.

The next gg lines contain your sequence of operations.

5 25 3
3 3 3 3 3
5
add 1
add 2
sub 3
sub 4
add 5

3 9 3
1 3 3
5
sqrt 2
sqrt 3
add 1
mul 2
mul 3

3 9 77
4 5 4
4
add 1
add 2
pow 2
sub 3

Hint

[Sample Explanation #1]

  • Add a1a_1 to xx. Now xx is 33.

  • Add a2a_2 to xx. Now xx is 66.

  • Subtract a3a_3 from xx. Now xx is 33.

  • Subtract a4a_4 from xx. Now xx is 00.

  • Add a5a_5 to xx. Now xx is 33.

[Sample Explanation #2]

  • Take the square root of a2a_2. Now a=[1,3,3]a = [1,\sqrt3,3].

  • Take the square root of a3a_3. Now a=[1,3,3]a = [1,\sqrt3,\sqrt3].

  • Add a1a_1 to xx. Now xx is 11.

  • Multiply xx by a2a_2. Now xx is 3\sqrt3.

  • Multiply xx by a3a_3. Now xx is 33.

[Sample Explanation #3]

  • Add a1a_1 to xx. Now xx is 44.

  • Add a2a_2 to xx. Now xx is 99.

  • Change xx into x2x^2. Now xx is 8181.

  • Subtract a3a_3 from xx. Now xx is 7777.

Translated by ChatGPT 5