#K45362. Taco Game Query Processing
Taco Game Query Processing
Taco Game Query Processing
You are given a series of queries to process over a dynamic set of integers. There are two types of queries:
+ x
: Add the integer x to the set. Note that duplicate values may be added.? x
: Find and output the smallest number in the set that is greater than or equal to x. If no such number exists, output \(-1\).
The queries are provided via standard input. The first line contains an integer \(Q\) representing the number of queries. Each of the next \(Q\) lines contains a query in the format described above.
Your task is to implement a solution that processes these queries and prints the result of each find query to standard output, one per line.
Note: Ensure that your code reads input from stdin and writes results to stdout.
inputFormat
The first line of input is an integer \(Q\) (\(1 \le Q \le 10^5\)) denoting the number of queries. The following \(Q\) lines each contain a query. Each query is in one of the following two formats:
+ x
: Add the integer x (\(|x| \le 10^9\)) to the set.? x
: Output the smallest number in the set that is greater than or equal to x.
outputFormat
For each query of type ? x
, output a single line containing the answer. If there is no number in the set that is greater than or equal to x, output \(-1\).
5
+ 3
+ 10
? 3
? 7
? 12
3
10
-1
</p>