n=int(input()) import sys data=[] for i in range(n): data.append(list(map(int,sys.stdin.readline().strip().split()))) #区间找点问题,按右端排序 data=sorted(data,key=lambda x:x[1]) res=set() for i in data: count=0 for k in range(i[0],i[1]+1): if k in res: count+=1 if count==2: break if count==0: res.add(i[-1]-1) res.add(i[-1]) if count==1: res.add(i[-1]) print(len(res))
def func(n, sections): sections.sort() bi = sections[0][0] select_nums = [bi - 1, bi] for section in sections: ai = section[1] bi = section[0] if ai <= select_nums[-2]: continue elif ai <= select_nums[-1]: select_nums.append(bi) else: select_nums.append(bi) select_nums.append(bi - 1) print(len(select_nums)) n = int(input()) sections = [] for i in range(n): ai, bi = map(int, input().split()) per_section = (bi, ai) sections.append(per_section) func(n, sections)
arr = [] n = int(input()) for _ in range(n): elem = list(map(int, input().split())) arr.append(elem) arr = sorted(arr, key = lambda x :x[1]) if len(arr)==1: print(2) else: select = [] k = range(arr[0][0], arr[0][1]+1) select.append(k[-2]) select.append(k[-1]) for i in range(1, len(arr)): elem = arr[i] right = elem[1] left = elem[0] count = 0 for j in select: if j>=left and j<=right: count +=1 if count==0: select.append(right-1) select.append(right) if count==1: select.append(right) if count==2: continue print(len(select))