#ds205. 线段树上二分

线段树上二分

Binary Search on Segment Tree

Problem Description

You are given nn numbers a1,a2,a3,…,ana_1, a_2, a_3, \dots, a_n.

You must support qq operations:

  1. 1 x d: set ax=da_x = d.
  2. 2 l r d: among al,al+1,al+2,…,ara_l, a_{l+1}, a_{l+2}, \dots, a_r, find the index of the first element that is ≥d\ge d; if no such element exists, output −1-1. In other words, find the smallest ii (l≤i≤rl \le i \le r) such that ai≥da_i \ge d.

Input Format

The first line contains two integers nn and qq (1≤n,q≤2×1051 \le n, q \le 2 \times 10^5).

The next line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1091 \le a_i \le 10^9).

The following qq lines each describe an operation of the form 1 x d or 2 l r d, with 1≤x≤n1 \le x \le n, 1≤l≤r≤n1 \le l \le r \le n, and 1≤d≤1091 \le d \le 10^9.

Output Format

For each query, output one line containing the answer.

Sample Input

5 5
1 2 3 4 5
2 4 5 5
1 5 1
2 1 5 3
1 3 2
2 1 3 3

Sample Output

5
3
-1

Constraints

1≤n,q≤2×1051 \le n, q \le 2 \times 10^5, 1≤ai,d≤1091 \le a_i, d \le 10^9, 1≤x≤n1 \le x \le n, 1≤l≤r≤n1 \le l \le r \le n.