#C5134. Dynamic Set Query

    ID: 48750 Type: Default 1000ms 256MiB

Dynamic Set Query

Dynamic Set Query

You are given a series of operations to perform on an initially empty set of integers. There are two types of operations:

  1. Add an integer (x) to the set. Note that the set stores unique elements only.
  2. Query the set: Given an integer (y), find and output the largest integer in the set that is less than or equal to (y). If no such element exists, output (-1).

You are required to process (n) operations. For query operations, print the result on a new line.

For example, given the operations below:

6 1 10 1 20 2 15 1 25 2 20 2 5

The expected output is:

10 20 -1

In the above, the first number in each line represents the type of operation where type 1 is an insertion and type 2 is a query. The equations used for this problem are straightforward:

For a query operation with input (y), we must find the maximum (x) in the set such that (x \leq y). If such an (x) does not exist, the output is (-1).

inputFormat

The first line of input contains a single integer (n) (the number of operations). The following (n) lines each contain an operation in one of the formats:

• "1 x" — add the integer (x) to the set. • "2 y" — query to find the largest integer in the set that is (\leq y).

All operations are given via standard input.

outputFormat

For each query operation (type 2), output the corresponding result on a new line to standard output. If there is no element satisfying the condition, output (-1).## sample

6
1 10
1 20
2 15
1 25
2 20
2 5
10

20 -1

</p>