#K58967. Tree Operations in a Secluded Valley

    ID: 30760 Type: Default 1000ms 256MiB

Tree Operations in a Secluded Valley

Tree Operations in a Secluded Valley

In a secluded valley, a unique set of trees exists where each tree has a distinct height. The forest guard receives a series of operations to manage these trees. There are three operations:

  • add h: Add a tree with height h. It is guaranteed that no tree with the same height already exists.
  • remove h: Remove the tree with height h. It is guaranteed that such a tree currently exists.
  • tallest_in_range l r: Query the tallest tree with height in the range $l \leq h \leq r$. If there are no trees in the range, output -1.

Your task is to process a sequence of these operations. For each query (tallest_in_range), output the answer on a new line.

inputFormat

The input is given via standard input in the following format:

The first line contains an integer QQ, the number of operations. Each of the following QQ lines contains one operation in one of the following formats:

• add h • remove h • tallest_in_range l r

It is guaranteed that all operations are valid.

outputFormat

For each tallest_in_range query, output the height of the tallest tree whose height lies in the inclusive range [l,r][l, r]. If no such tree exists, output -1. Each result should be printed on a new line.## sample

6
add 5
add 10
add 15
tallest_in_range 1 10
remove 10
tallest_in_range 1 10
10

5

</p>