树啊树

校门外的树

https://ac.nowcoder.com/acm/problem/16649

直接上代码:

#include<iostream>
using namespace std;

int a[100050] = {1};

int main()
{
    int l, m;
    cin >> l >> m;

    for (int i = 1; i <= m; i++)
    {
        int x, y;
        cin >> x >> y;

        a[x]--;          //左端减一
        a[y + 1]++;      //右端右移减一
    }

    int ans = 0;         //计数

    for (int i = 1; i <= l; i++)
    {
        a[i] += a[i - 1];    //求前缀和

        if (a[i] > 0)
        {
            ans++;
        }
    }

    if (a[0] > 0)
    {
        ans++;
    }

    cout << ans<<endl;

    return 0;
}
全部评论

相关推荐

兄弟们,实习都是在接各种api,该怎么包装简历
仁者伍敌:感觉我自己做小项目也是各种api啊,我要怎么包装简历
点赞 评论 收藏
分享
牛客92804383...:在他心里你已经是他的员工了
点赞 评论 收藏
分享
程序员小白条:找的太晚,别人都是大三实习,然后大四秋招春招的,你大四下了才去实习,晚1年
点赞 评论 收藏
分享
07-03 16:02
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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