CodeForces1000C

CodeForces1000C

本来以为是道水题,然后我看到了数据范围,当时就有点方,觉得这题难死了
然鹅,我冷静了一会儿发现,离散化一下好像就变成了真水题,但是...排序离散化我搞了半天不知道哪里有毛病...于是....
抱着试试的心态我试了试 \(map\) , 然后就一帆风顺地 \(AC\)

不考虑高达 \(10^18\) 的区间范围的话,就只需要做一遍差分,然后做一遍前缀和统计答案就好了.
离散化之后也一样做.

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <map>
#define int long long

using std::map ;

const int N = 2e5 + 100 ;

map < int , int > mk ;
int n , ans[N] ;

signed main () {
    scanf ("%lld" , & n ) ;
    for (int i = 1 , u , v ; i <= n ; ++ i) {
        scanf ("%lld%lld" , & u , & v ) ;
        ++ mk[u] ; -- mk[v+1] ;
    }
    int cnt = 0 , last = 0 ;
    for (auto it = mk.begin () ; it != mk.end () ; ++ it) {
        ans[cnt] += ( it->first - last ) ;
        last = it->first ; cnt += it->second ;
    }
    for (int i = 1 ; i <= n ; ++ i) printf ("%lld " , ans[i] ) ;
    system ("pause") ; return 0 ;
}

猜你喜欢

转载自www.cnblogs.com/Equinox-Flower/p/11393013.html