12728 - Container Tree   

Description

Please do problem 12727 first.

This time, it's about BST. Also, you'll need to define some of the functions in iterator. It would probably help if you read the partial judge source code from 12727 again.

You should know what to do by reading the .h file. However, the following are the specs:

  void insert(const value_type &val); // insert val in tree if val not exist
  iterator lower_bound(const value_type &val); // return iterator to the node whose value is the least among those greater than or equal to val (if none, return end())

 

Edited 5/16: lower_bound: those greater than *or equal to* val

Input

T
N_1
Q_1 Q_2 ... Q_N_1
N_2
Q_1 Q_2 ... Q_N_2
...
N_T
Q_1 Q_2 ... Q_N_T

1 <= T <= 500
1 <= N <= 500
1 <= Q <= 500

T is the number of test cases.
N_i is the number of queries in the i'th test case.
For each Q, you are asked to print the least value greater than or equal to Q in the tree (if none do nothing), and insert Q into the tree.

Output

For each Q, print the least value greater than or equal to Q in one line.

Sample Input  Download

Sample Output  Download

Partial Judge Code

12728.cpp

Partial Judge Header

12728.h

Tags




Discuss