Processing math: 100%
Sorting queries - MarisaOJ: Marisa Online Judge

Sorting queries

Time limit: 3000 ms
Memory limit: 256 MB
Given an array of integers a consisting of n integers. You are given q queries of the following types: - 0lr: Sort the integers al,al+1,…,ar in ascending order. - 1lr: Sort the integers al,al+1,…,ar in descending order. After q queries, determine the value at position m in the array a. ### Input - The first line contains two integers n and q. - The next q lines each contain a query in the format described above. - The last line contains an integer m. ### Output - Print a single integer, the value at position m after q queries. ### Constraints - 1≤n,q≤105. - 1≤m,ai≤n. ### Example Input: 53154230241350142 Output: 2