Merged length commands

Revision en1, by bitch_house, 2020-07-21 00:29:47

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.

Tags #query

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English bitch_house 2020-07-21 00:31:10 20 Tiny change: 'val [L,R].\n- remove' -> 'val [L,R].<br>\n- remove'
en1 English bitch_house 2020-07-21 00:29:47 724 Initial revision (published)