#K72797. Array Operations
Array Operations
Array Operations
Given an array \(nums\) of length \(n\) and \(m\) operations, apply each operation sequentially. There are three types of operations:
- Add x: Add the integer \(x\) to each element of the array.
- Multiply x: Multiply each element of the array by \(x\).
- SetMax x: Replace each element with \(\min(\text{num}, x)\), ensuring that no element exceeds \(x\).
More formally, let the array be \(nums = [a_1, a_2, \dots, a_n]\). After applying an operation:
- For "Add x": \(a_i \gets a_i + x\) for \(1 \leq i \leq n\).
- For "Multiply x": \(a_i \gets a_i \times x\) for \(1 \leq i \leq n\).
- For "SetMax x": \(a_i \gets \min(a_i, x)\) for \(1 \leq i \leq n\).
Output the final state of the array after all operations are applied.
inputFormat
The input is read from stdin and consists of multiple lines:
- The first line contains two integers (n) and (m), where (n) is the number of elements in the array and (m) is the number of operations.
- The second line contains (n) integers separated by spaces, representing the initial array.
- Each of the next (m) lines contains an operation in the format:
op x
, whereop
is one of "Add", "Multiply", or "SetMax", and (x) is an integer.
outputFormat
Print a single line to stdout containing the final state of the array. The numbers should be separated by a space.## sample
5 1
1 2 3 4 5
Add 2
3 4 5 6 7