BST Problem

View as PDF

Submit solution

Points: 1
Time limit: 2.0s
Memory limit: 488M

Problem type

Problem Statement

You are given n queries, each of the following form, either:

  • SEARCH x where x is some integer, or
  • INSERT x where x is some integer Imagine you start with an empty collection of numbers. When you see INSERT x you should add x to your collection of numbers. Every time you see SEARCH x you should determine the first thing less than or equal to x in your collection of numbers. ## Input Format

Your first line will contain n. Your next n lines will contain one query each.

Output Format

For each SEARCH x query you should output the first thing less than or equal to x in your current collection of numbers. If there is nothing less than or equal to x, output 1.

Constraints

  • 1n105
  • 109ai109 ## Sample Cases
Input 1
Copy
7
INSERT 10
SEARCH 9
INSERT 3
INSERT 4
INSERT 8
SEARCH 3
SEARCH 7
Output 1
Copy
-1
3
4

Comments

There are no comments at the moment.