Range Variation Query#622

Range Variation Query

1 second
122.174 megabytes
Hard (≈1650)

The sequence a_n is defined by the following formula:

a_n = n^2~mod~12345 + n^3~mod~23456

It is necessary to repeatedly handle requests of two types:

Input

The first line contains one natural number k~(k \le 10^5) — the number of requests. Each of the following lines describes one request with two integers x_i and y_i:

  • If x_i > 0, it is necessary to find the difference between the maximum and minimum values in the segment a_{xi} ... a_{yi}~(1 \le x_i \le y_i \le 10^5).

  • If x_i < 0, it is necessary to assign the element a_{-x_i}~(-10^5 \le x_i \le -1) the value y_i~(|y_i| \le 10^5).

Output

For each request of the first type, output on a separate line the difference between the maximum and minimum values on the specified segment.

Examples

Example 1

Loading
Loading