N is the number of vertical lines M is the number of line segments
let N = 4 ; let M = 8 ; let size = 2000000 + 2 ; let pref = Array . from ( { length : size } , ( _ , i ) => 0 ) ; let lines = [ - 5 , - 3 , 2 , 3 ] ;