You can use a data structure with unrelated sets .
Imagine our subset as disjoint. Each element of a disjoint set is an element of a subset i(including the always-present zero), combined with all the missing elements in the set, which are larger than iand smaller than the next given element.
Example:
n = 10
s = [1, 4, 7, 8], disjoint-set = [{0}, {1,2,3}, {4,5,6}, {7}, {8, 9, 10}]
s = [3, 5, 6, 10], disjoint-set = [{0, 1, 2}, {3, 4}, {5}, {6, 7, 8, 9}, {10}]
, n+1 ( ). , leftmost .
leftmost(i) - leftmost disjoint-set, i.
leftmost(i) Find . i leftmost, . : O(α(n))
, i , i leftmost(i). ( i > 0), i .
pred(i) leftmost(i), i leftmost(i-1), i . : O(α(n))
delete(i) , i . i , , i ( , i-1). Union . leftmost leftmost(i-1). : O(α(n))
. " , " , .