Length of the union
Consider a set of segments on a line, each defined by integer endpoints. Initially, this set is empty, but you can add or remove segments from it. After each operation—whether adding or removing a segment—you must output the total length of the union of all segments currently in the set.
Input
The first line of the input contains an integer 1 ≤ n ≤ 100,000, representing the total number of operations to be performed. Each of the following n lines describes an operation. The first character is "+" for adding a segment or "-" for removing a segment. This character is followed by two integers, separated by a space, which represent the left and right endpoints of the segment. The absolute values of these endpoints do not exceed 1,000,000,000. It is guaranteed that only segments previously added to the set will be removed. Identical segments can be added multiple times, and each instance is treated as a separate segment.
Output
The output should consist of exactly n numbers, each on a new line. Each number represents the total length of the union of all segments in the set after each of the n operations, whether it is an addition or a removal.