Task
Given an array with natural numbers that are less than or equal to , and queries of the following types:
- : The largest values in the array will become equal to their value modulo . If we have multiple values equal to the -th value, we will apply the operations from left to right. If a value was and we apply the operation with , that value will become .
- : The value at position becomes .
- : Display the maximum value in the array.
Since the committee does not want to spend time chatting with you, you must solve the problem as fast as possible, or else they'll get upset with you.
Input data
The first line of the input file mod.in
contains two integers, and .
The next line contains the initial array , which has natural elements.
The next lines contain the queries, according to the description in the statement, being of type , , or .
Output data
The output file mod.out
will contain as many numbers as there are type queries, printing the maximum value at that moment.
Constraints and clarifications
- ;
- ;
We will denote the maximum value in the array or from one of the updates with . Then we have the following subtasks:
# | Points | Constraints |
---|---|---|
1 | 16 | |
2 | 24 | |
3 | 23 | |
4 | 10 | |
5 | 27 | No other constraints |
Example
mod.in
7 8
12 4 8 10 9 7 8
1 2 5
3
2 3 11
1 5 8
2 6 4
3
2 3 4
3
mod.out
9
4
4
Explanation
After the first operation, the array will look like this: . It can be observed that the first and the fourth values have been reduced (from became and became ).
After the third operation, the array will look like this: .
After the fourth operation, the array will look like this: .
After the fifth operation, the array will look like this: .
After the seventh operation, the array will look like this: .