值周

值周

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

区间上修改,操作简单,就考虑下差分;

#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
#define int long long
const int maxn=1e8+6;
int ans,a[maxn];
signed main()
{
    int l,m;
     scanf("%lld %lld",&l,&m);
    for(int i=1;i<=m;i++)
    {
        int x,y;
        scanf("%lld %lld",&x,&y);
        a[x]++,a[y+1]--;
    }
    int h=0;
    for(int i=0;i<=l;i++)
    {
         h+=a[i];
        if(h==0) ans++;
    }
    cout<<ans;
}
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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