Queries for Subarray Beauty#330

Queries for Subarray Beauty

2.5 seconds
512 megabytes
Very hard

Let's call the weight of an array of integers of length the absolute value of the sum of its elements, i.e., |b_1+b_2+...+b_m|.

We define the beauty of a partition of array into several subarrays as the minimum weight among the weights of the subarrays. Formally, the beauty of a partition of array into subarrays [c_1,\ldots,c_{p_1}],[c_{p_1+1},\ldots,c_{p_2}],\ldots,[c_{p_{k-1}+1},\ldots,c_{p_k}], where 1 \leq p_1 < p_2 < \ldots < p_{k-1} < p_k = n, is the value \min(|c_1+\ldots+c_{p_1}|,|c_{p_1+1}+\ldots+c_{p_2}|,\ldots,|c_{p_{k-1}+1}+\ldots+c_{p_k}|). For example, the partition of the array [3,-6,4,5,-8] into subarrays [3,-6],[4],[5,-8] has a beauty of \min(|3+(-6)|,|4|,|5+(-8)|)=\min(3,4,3)=3.

We define the beauty of an array as the maximum beauty among all possible partitions into subarrays.

An array of integers of length is given.

You need to perform queries. The queries can be of two types:

  1. find the beauty of the subarray consisting of elements [a_{l},a_{l+1},\ldots,a_r], where (, ) are the query parameters;

  2. replace the element a_x with , where (, ) are the query parameters.

Input

The first line contains two integers , (1\le n, q\le 10^6) — the length of array and the number of queries, respectively.

The second line contains integers a_1, a_2, \ldots, a_n (-10^9\le a_i\le 10^9) — the elements of array .

The next lines contain three integers each. The first of the numbers, type_i (1 \le type_i \le 2), denotes the type of the query. Queries of the first type are given in the format "1 l r" (1\le l\le r\le n), and queries of the second type are given in the format "2 x v" (1\le x\le n, -10^9\le v\le 10^9).

Output

For each query of the first type, output a single integer — the beauty of the corresponding subarray.

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading

Note

In the first example, for the third query, the maximum beauty of the partition of the array [-3,4,2,-5] is achieved when partitioned into subarrays [-3],[4,2],[-5].

In the second example, for the first query, the maximum beauty of the partition of the array [1,-2,3,-4] is achieved when partitioned into subarrays [1,-2,3],[-4].

Scoring

  1. ( points): type_i = 1 for 1\le i\le q; a_i > 0 for 1\le i\le n;

  2. ( points): type_i = 1 for 1\le i\le q; n,q \le 1000;

  3. ( points): type_i = 1 for 1\le i\le q; n,q \le 2 \cdot 10^5, for each query there exists an optimal division into no more than subarrays;

  4. ( points): type_i = 1 for 1\le i\le q; q \le n \le 2 \cdot 10^5, l_i = 1, r_i = i for 1\le i\le q;

  5. ( points): type_i = 1 for 1\le i\le q; n,q \le 2 \cdot 10^5, -5 \le \sum\limits_{j=1}^{i} a_j \le 5 for 1\le i\le n;

  6. ( points): type_i = 1 for 1\le i\le q; n,q \le 2 \cdot 10^5;

  7. ( points): type_i = 1 for 1\le i\le q;

  8. ( points): n,q \le 2 \cdot 10^5;

  9. ( points): without additional constraints.