Yet another square root decomposition problem - MarisaOJ: Marisa Online Judge

Yet another square root decomposition problem

Time limit: 2500 ms
Memory limit: 512 MB
Given an array A of n integers, there are q queries, each falling into one of two types: - 1lrxy: For all l≤i≤r where Ai=x, replace Ai with y. - 2lrk: Find the k-th smallest value in the range Al,Al+1,...,Ar. ### Input - The first line contains two integers n,q. - The second line contains n integers Ai. - The next q lines each contain a query in the specified format. ### Output - Print an integer as the answer for each query of type 2. ### Constraints - 1≤n,q,Ai,x,y≤105. - 1≤l≤r≤n. ### Example Input: 99145523122145112111299129912782189232473267113643 Output: 122231