mod

Time limit: 2s Memory limit: 64MB Input: mod.in Output: mod.out

Task

Given an array with nn natural numbers that are less than or equal to 10910^9, and qq queries of the following types:

  • 1 x k1 \ x \ k: The largest xx values in the array will become equal to their value modulo kk. If we have multiple values equal to the xx-th value, we will apply the operations from left to right. If a value was 1515 and we apply the operation with k=9k = 9, that value will become 66.
  • 2 p x2 \ p \ x: The value at position pp becomes xx.
  • 33: 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, nn and qq.

The next line contains the initial array vv, which has nn natural elements.

The next qq lines contain the queries, according to the description in the statement, being of type 11, 22, or 33.

Output data

The output file mod.out will contain as many numbers as there are type 33 queries, printing the maximum value at that moment.

Constraints and clarifications

  • 1N,Q200 0001 \leq N, Q \leq 200 \ 000;
  • 1MAXVAL1091 \leq MAXVAL \leq 10^9;

We will denote the maximum value in the array or from one of the updates with MAXVALMAXVAL. Then we have the following subtasks:

# Points Constraints
1 16 N,Q,MAXVAL2 000N, Q, MAXVAL \leq 2 \ 000
2 24 MAXVAL100MAXVAL \leq 100
3 23 N,Q,MAXVAL50 000N, Q, MAXVAL \leq 50 \ 000
4 10 MAXVAL106MAXVAL \leq 10^6
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: [2,4,8,0,9,7,8][2, 4, 8, 0, 9, 7, 8]. It can be observed that the first and the fourth values have been reduced (from 1212 became 22 and 1010 became 00).

After the third operation, the array will look like this: [2,4,11,0,9,7,8][2, 4, 11, 0, 9, 7, 8].

After the fourth operation, the array will look like this: [2,4,3,0,1,7,0][2, 4, 3, 0, 1, 7, 0].

After the fifth operation, the array will look like this: [2,4,3,0,1,4,0][2, 4, 3, 0, 1, 4, 0].

After the seventh operation, the array will look like this: [2,4,4,0,1,4,0][2, 4, 4, 0, 1, 4, 0].

Log in or sign up to be able to send submissions!