cf1000 C. Covered Points Count

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
map<ll ,int > mp;
ll cnt[200010];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        ll l,r;
        scanf("%lld%lld",&l,&r);
        mp[l]++;
        mp[r+1]--;    
    }
    ll start;
    int num=0;
    for(auto it=mp.begin();it!=mp.end();it++)
    {
        if(it==mp.begin())
        {
            start=it->first;
            num+=it->second;
        }
        else
        {
            //printf("%d %d\n",num,(it->first) - start);
            cnt[num]+=( (it->first) - start);//cnt记录的是点的个数,所以会爆int!!! 
            start=(it->first);
            num+=it->second;
        }
    }
    for(int i=1;i<=n;i++)
       printf("%lld ",cnt[i]);
    printf("\n");
}

前缀和的变体。

猜你喜欢

转载自www.cnblogs.com/lishengkangshidatiancai/p/10348100.html
今日推荐