#K47762. Array Operations Challenge

    ID: 28271 Type: Default 1000ms 256MiB

Array Operations Challenge

Array Operations Challenge

You are given an array of integers and a sequence of operations to perform on the array. The operations include increment, multiply, reverse, and swap.

Operation details:

  • increment n: Add \(n\) to every element, i.e. \(a_i = a_i + n\).
  • multiply n: Multiply every element by \(n\), i.e. \(a_i = n \times a_i\).
  • reverse: Reverse the order of the array.
  • swap i j: Swap the elements at positions \(i\) and \(j\) (0-indexed).

Your task is to apply the operations in the given order and output the resulting array.

inputFormat

The input is given via standard input (stdin) and consists of multiple test cases. The first line contains an integer \(T\), the number of test cases. For each test case, the following input is provided:

  1. A line with two integers \(n\) and \(m\): the number of elements in the array and the number of operations.
  2. A line with \(n\) space-separated integers representing the array.
  3. \(m\) lines, each containing a single operation in one of the following forms: increment n, multiply n, reverse, or swap i j.

outputFormat

For each test case, output a single line (to stdout) containing the resulting array after performing all operations. The array elements should be printed as space-separated integers.

## sample
2
3 1
1 2 3
increment 2
4 2
1 2 3 4
swap 0 3
reverse
3 4 5

4 3 2 1

</p>