P4119 [Ynoi2018] Future Diary

Background

So, Xiaoxue’s (pinyin) future belongs to Yuno’s~ ![](https://cdn.luogu.com.cn/upload/pic/13174.png) Hmm... I know what your future will be like. Listen up, I am Yuno Gasai. ![](https://cdn.luogu.com.cn/upload/pic/13175.png) Because Xiaoxue changed the future, the three of them could be together... Why... That makes me the bad guy... ![](https://cdn.luogu.com.cn/upload/pic/13176.png) I won’t stab. Because... this is the future. This... is my home. ![](https://cdn.luogu.com.cn/upload/pic/13177.png)

Description

Yuno Gasai gave you a sequence $a$ of length $n$, with $m$ operations. 1. Replace all occurrences of $x$ with $y$ within the interval $[l, r]$. 2. Query the $k$-th smallest value within the interval $[l, r]$.

Input Format

The first line contains two integers $n$ and $m$. The second line contains $n$ integers representing the sequence $a$. The next $m$ lines: `1 l r x y`: Replace all $x$ in $[l, r]$ with $y$. `2 l r k`: Query the $k$-th smallest value in $[l, r]$.

Output Format

For each query, output one integer as the answer.

Explanation/Hint

Idea: f321dd, Solution: f321dd & nzhtl1477, Code: nzhtl1477 & Claris, testdata: nzhtl1477 & Juan_feng. Constraints: $1 \le n, m, a_i \le 10^5$. By f321dd & nzhtl1477 & Claris. Translated by ChatGPT 5