Problem 715 · Hard
Keep disjoint half-open intervals; adding merges neighbours, removing splits them, and queries check one interval.
Open the interactive visualisation