#P1325. The Smallest Open Interval

The Smallest Open Interval

The Smallest Open Interval

题目描述

Given a set SS of points on the xx -axis. For any point pp , you are suppose to find the smallest open interval that contains pp, provided that the two ends of the interval must be in SS.

输入格式

Each input file contains one test case. Each case consists of several lines of commands, where each command is given in the format:

cmd num

where cmdcmd is either II for "insert", or QQ for "query", or EE for "end"; and numnum is an integer coordinate of a point on the xx-axis. It is guaranteed that num is in the range[109,109][-10^9, 10^9] . The input is ended by EE. It is guaranteed that there are no more than 10510^5 distinct points in SS, and so is the number of queries. The total number of commands (E not included) is no more than 3×1053×10^5.

输出格式

For each II case, insert numnum into SS. For each QQ case, output the smallest open interval that contains num in the format (S1,S2)(S_1,S_2), where both S1 and S2S_1\ and\ S_2 must be in SS. On the other hand, if num is no larger than the smallest point in SS, s1 shall be replaced by inf-inf, representing negative infinity; or if num is no smaller than the largest point in SS, s2s2 shall be replaced by +inf+inf , representing positive infinity. It is guaranteed that there must be at least 11 point in SS before the first query.

样例 #1

样例输入 #1

I 100
Q 100
I 0
I 33
I -200
Q 25
Q 33
Q -200
Q 200
E

样例输出 #1

(-inf, +inf)
(0, 33)
(0, 100)
(-inf, 0)
(100, +inf)