题解 | 校门外的树
校门外的树
https://www.nowcoder.com/practice/0e8cfc82936048769af45967f3c4ef7e
shu,n = map(int,input().split())
lu=[]
for i in range (n):
l,r =map(int,input().split())
lu.append([l,r])
lu.sort(key=lambda x: x[0])
colu=[lu[0]]
for cur in lu[1:]:
last = colu[-1]
if cur[0]<=last[1]:
colu[-1]=[last[0],max(last[1],cur[1])]
else:
colu.append(cur)
#print(colu)
total=0
for i in range(len(colu)):
total+=colu[i][1]-colu[i][0]+1
print(shu+1-total)
区间覆盖处理思路
