题解 | 校门外的树

校门外的树

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)  
    

区间覆盖处理思路

全部评论

相关推荐

不愿透露姓名的神秘牛友
2025-12-07 15:50
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务