Skip to main content

Practice · 3 of 5

Replacement Search

CHALLENGE
Difficulty: intermediate+25 XP

**Description:** Maintain a multiset of n initial values. Process q operations: + x inserts x; - x erases **one** occurrence of x (guaranteed present); ? x prints the smallest stored value **>= x**, or -1 if none exists. **Input:** Line 1: n q (1 <= n, q <= 2*10^5). Line 2: n initial values (|a_i| <= 10^9). Next q lines: an operation as described (|x| <= 10^9). **Output:** One line per ? operation. **Example:** 3 3 / 2 5 8 / ? 6 / + 6 / ? 6 -> 8 / 6.

Back to lesson: Practice: STL Problem Set