Apple trees 4 - MarisaOJ: Marisa Online Judge

Apple trees 4

Time limit: 1000 ms
Memory limit: 256 MB
Marisa planted $n$ apple trees in a row. Each tree, denoted as the $i^{th}$ tree, can initially grow apples of size $A_i$. However, due to the rain, some trees mutate, resulting in changes to the sizes of their apples. There are $q$ event that happen chronological order: - `1 i x`: apples on tree $i$ change their size to $x$. - `2 l r k`: For her research purposes, Marisa conducts a query in the form of $(l, r, k)$.She needs to find the $k^{th}$ smallest apple size among the trees in the range $[l, r]$. Please help her answering these queries. ### Input - The first line contains two integers $n,q$. - The second line contains $n$ integer $A_i$. - The next $q$ lines, each line contains a query in the aforementioned format. ### Output - Print an integer, which represents the answer for each query of type 2. ### Constraints - $1 \le n,q \le 10^5$ - $1 \le A_i \le 10^9$. - $1 \le l \le r \le n$. - $1 \le k \le r - l + 1$. - $1 \le i \le n$. - $1 \le x \le 10^9$. ### Example Input: ``` 5 3 3 7 2 1 8 2 1 3 1 1 2 2 2 2 4 3 ``` Output: ``` 2 2 ```
Topic
Binary search
Data structure
Rating 2200
Solution (0) Solution