Good triangles#524

Good triangles

4 seconds
256 megabytes
Very hard (≈2050)

You are given an array of magic sticks , where stick -th stick has length a_i. We call an array of sticks good, if there exist a triplet (1 \le i < j < k \le |b|), such that there exists a non-degenerate triangle with sides b_i, b_j and b_k.

You are asked to handle queries of two types:

Input

The first line of input contains two integers and (1 \le n,q \le 5 \cdot 10^5) — length of array of magic sticks and number of queries.

The second line of input contains integers a_i (1 \le a_i \le 10^6) — lengths of magic sticks in the array .

Each of the following lines contains one query of one of the following types:

  • (1 \le i \le n, 1 \le x \le 10^6);

  • (1 \le l \le r \le n).

Output

For each query of type print a single line with a single integer — the maximum number of non-empty contiguous subsegments into which the segment can be partitioned so that each subsegment is good. If the segment cannot be split into non-empty contiguous subsegments print .

Examples

Example 1

Loading
Loading

Note

The initial array is a = [1, 3, 5, 4, 7, 5, 4, 3, 9, 8].

Query "2 1 10": We can partition the whole array into good subsegments: [1, 3, 5, 4], [7, 5, 4], [3, 9, 8].

  • [1, 3, 5, 4] is good: sticks of length , , form a triangle (3 + 4 > 5).

  • [7, 5, 4] is good: sticks of length , , form a triangle (4 + 5 > 7).

  • [3, 9, 8] is good: sticks of length , , form a triangle (3 + 8 > 9).

Query "1 3 3": The array becomes a = [1, 3, 3, 4, 7, 5, 4, 3, 9, 8].

Query "2 1 10": We can partition the whole array into good subsegments: [1, 3, 3], [4, 7, 5], [4, 3, 9, 8].

  • [1, 3, 3] is good: sticks of length , , form a triangle (1 + 3 > 3).

  • [4, 7, 5] is good: sticks of length , , form a triangle (4 + 5 > 7).

  • [4, 3, 9, 8] is good: sticks of length , , form a triangle (4 + 8 > 9).

Query "2 1 7": The subarray is [1, 3, 3, 4, 7, 5, 4]. We can partition it into good subsegments: [1, 3, 3] and [4, 7, 5, 4].

  • [1, 3, 3] is good: 1 + 3 > 3.

  • [4, 7, 5, 4] is good: sticks of length , , form a triangle (4 + 4 > 5).

Query "2 3 8": The subarray is [3, 4, 7, 5, 4, 3]. We can partition it into good subsegment: [3, 4, 7, 5, 4, 3].

  • [3, 4, 7, 5, 4, 3] is good: sticks of length , , form a triangle (3 + 4 > 5).

Scoring

  1. ( points) n,q \le 1000, there are no update queries;

  2. ( points) n,q \le 1000;

  3. ( points) there are no update queries;

  4. ( points) a_i \le 100, for each in queries it is less than or equal to ;

  5. ( points) n \le 10^5;

  6. ( points) no additional restrictions.