QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 256 MB Total points: 100 Hackable ✓

#14559. Parallel Computing

Statistics

This problem has no input. Your code only needs to output the solution.

We have a parallel computing machine $M$. It has a fixed block of continuous memory that can hold 4096 32-bit unsigned integers. For convenience, we denote this memory as an array mem[4096].

Machine $M$ can only execute very simple parallel instructions. Specifically, one parallel instruction can perform up to 32 operations of the same type simultaneously. A parallel instruction is of the form:

op k
a1 a2 a3 ... ak
b1 b2 b3 ... bk
c1 c2 c3 ... ck

This represents performing $k$ ($1 \le k \le 32$) operations simultaneously. For the $i$-th operation, it calculates the result of mem[ai] op mem[bi] and then writes it to mem[ci]. Note that within a single instruction, if there exist two calculations $i$ and $j$ such that $i \neq j$ and $c_i = a_j$ or $c_i = b_j$ or $c_i = c_j$, then a parallel conflict occurs, which may lead to undefined behavior.

The operations op mentioned above include the following 5 types:

  • add: calculates $a + b$.
  • sub: calculates $a - b$.
  • mul: calculates $a \times b$.
  • max: calculates the maximum of $a$ and $b$.
  • min: calculates the minimum of $a$ and $b$.

Currently:

  • mem[0, 1023] contains an integer array $X$ of length 1024, where each element $x_i$ ($0 \le i \le 1023$) satisfies $0 \le x_i \le 10^4$.
  • mem[1024, 2047] contains an integer array $Y$ of length 1024, where each element $y_i$ ($0 \le i \le 1023$) is 0 or 1.

You need to use this parallel machine to calculate the prefix sums of segments of array $X$.

Specifically, let $y_{-1} = y_{1024} = 1$. Then for any segment $[l, r]$ ($0 \le l \le r \le 1023$) such that $y_l = y_{l+1} = \dots = y_r = 0$ and $y_{l-1} = y_{r+1} = 1$, you need to transform the subarray $x_l, x_{l+1}, \dots, x_r$ into the prefix sum array of that subarray.

To better understand the problem, we illustrate with an array of length 10: if array $X$ is $1, 2, 3, 4, 5, 6, 7, 8, 9, 10$ and array $Y$ is $0, 0, 0, 1, 1, 0, 0, 1, 0, 0$, then you need to execute some instructions to transform array $X$ into: $1, 3, 6, ?, ?, 6, 13, ?, 9, 19$. Here, $?$ can be any 32-bit unsigned integer.

Please construct no more than 200 parallel instructions to complete this task. You can assume that the parallel machine automatically initializes before executing instructions, placing the test data's array $X$ in mem[0, 1023] and the test data's array $Y$ in mem[1024, 2047], with all other memory initialized to 0. Then, the parallel machine will execute the parallel instructions you constructed in order. After that, you need to ensure that the array $X$ in memory (mem[0, 1023]) contains the correct result.

Input

There is no input for this problem.

Output

The first line outputs an integer $n$ ($0 \le n \le 200$), representing the length of the instruction sequence you constructed. Then, output $n$ instructions, each containing 4 lines, in the form:

op k
a1 a2 a3 ... ak
b1 b2 b3 ... bk
c1 c2 c3 ... ck

Where op is a string belonging to add, sub, mul, max, min, representing the operation type. Where $k$ ($1 \le k \le 32$) represents the number of operations performed in parallel in this instruction. For $a_i, b_i, c_i$ ($1 \le i \le k$), they must satisfy $0 \le a_i, b_i, c_i \le 4095$. There may be multiple correct outputs for this problem; you only need to output one of them.

Examples

Input 1

(none)

Output 1

2
add 8
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7
mul 4
0 1 2 3
4 5 6 7
8 9 10 11

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.