Codeforces 1000C Covered Points Count 【前缀和】【数据结构】

#include<iostream>
#include<map>
using namespace std;

map<long long,int> m;
long long count[200005];

int main(){
    int n; cin>>n;
    for(int i=1;i<=n;i++){
        long long start,end; scanf("%lld%lld",&start,&end);
        m[start]++; m[end+1]--;
    }    
    
    long long last=0;
    int cnt=0;
    
    //考虑每个区间 
    for( map<long long,int>::iterator it = m.begin(); it!=m.end(); it++){
        if( it==m.begin() ) { last=it->first; cnt+=it->second;  continue; }
        count[ cnt ] += it->first - last;
        last=it->first; 
        cnt+=it->second;
    }
    
    for(int i=1;i<=n;i++) cout<<count[i]<<" ";
    
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/ZhenghangHu/p/9239757.html