Number Queries

4

1 votes
Datastructures, Dynamic Programming, Algorithms, Hard
Problem

You are given an array A of N numbers and you need to answer Q queries of 2 types on it. In the first type query, you are given an integer X and you need to subtract X from all numbers with value greater than or equal to X. In the second type query, you are given 3 integers L, R and X, and you need to print the Xth smallest number with value between L and R (both inclusive). If there are less than X numbers with value between L and R, then print L.

Input:

The first line contains 2 space separated integers N and Q, denoting the number of elements in the array A and the number of queries. Second line contains N space separated integers, denoting the elements of the array A. Each of the next Q lines describe a query. If it is a first type query, you will be given 2 space separated integers where the first integer would be 1, denoting that it is a first type query and second integer would be X, as defined in the problem statement. If it is a second type query, you will be given 4 space separated integers where the first integer would be 2, denoting that it is a second type query and next 3 integers would be L, R and X, as defined in the problem statement.

Output:

For each query of the second type, print the Xth smallest number with value between L and R. If there are less than X numbers with value between L and R, then print L.

Constraints:

1N,Q2×105

1Ai1018

1LR1018

1XN

Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

The 3 numbers between 2 and 20 are 2, 3 and 6.

Editor Image

?