Set - MarisaOJ: Marisa Online Judge

Set

Time limit: 1000 ms
Memory limit: 256 MB
Given an initially empty set $S$, there are $q$ queries, each of the following format: - `1 x`: Insert an element $x$ into the set. - `2 x`: If at least one element $x$ exists in the set, remove **one** element $x$ from the set. - `3 x`: Find the smallest value greater than $x$. - `4 x`: Find the largest value not exceeding $x$. The set $S$ can contain multiple elements with the same value. ### Input - The first line contains an integer $q$. - The next $q$ lines, each line contains a query in the specified format. ### Output - For each query of type $3,4$, print an integer as the answer if it exists; otherwise, print `-1`. ### Constraints - $1 \le n,q \le 10^5$. - $1 \le x \le 10^9$. ### Sample test Input ``` 8 4 5 1 2 1 3 1 2 3 2 1 5 2 3 4 4 ``` Output: ``` -1 3 2 ```