I recently came across a problem which reduced to the following:-

Initially, we are provided a number line. Every second, we are being given one of the following two kind of commands

- add(L,R) : If we receive this command, we have to place a stick in the interval [L,R].

- remove(L,R) : We receive this command only if we received add(L,R) in an earlier time. Remove a stick [L,R] added earlier

After every second, we have to tell the total merged length. In a merged length, we count the overlap length of two or more sticks only once. For example if [1,5] and [4,7] sticks were placed, their mergal is [1,7] and mergal length 6. It would be great if someone can help me approach the problem.