you give n color segment number line each segment color red blue the ith segment represent tuple c_i l_i r_i the segment contain point range l_i r_i inclusive color denote c_i c_i 0 red segment c_i 1 blue segment we segment different color connect share common point two segment belong group connect directly sequence directly connect segment find number group segment