#C11143. Array Query Processor
Array Query Processor
Array Query Processor
You are given an array of n integers and m queries. The queries will instruct you to modify the array or retrieve information from it. The queries can be of the following five types:
- Type 1:
1 X
– Add an integer X to each element of the array. Mathematically, for every index i, update \(a_i = a_i + X\). - Type 2:
2 Y
– Multiply each element of the array by Y. That is, \(a_i = a_i \times Y\). - Type 3:
3 Z
– Perform integer division on each element by Z. Each element is updated as \(a_i = \lfloor a_i / Z \rfloor\). (Note: \(\lfloor \cdot \rfloor\) denotes the floor function.) - Type 4:
4
– Reverse the array. - Type 5:
5
– Determine the maximum element of the current array and report it.
Process the queries in the order they are given. For each query of Type 5, output the maximum element at that moment on a new line.
inputFormat
The first line contains two space-separated integers n and m, representing the size of the array and the number of queries respectively.
The second line contains n space-separated integers, the elements of the array.
The next m lines each contain a query in one of the following formats:
1 X
2 Y
3 Z
4
5
outputFormat
For each query of type 5
, output the maximum number in the array at that instance, each on a separate line.
5 6
1 2 3 4 5
1 10
2 2
4
3 2
5
2 3
15
</p>