1000C.md (1881B)
1 Source: https://codeforces.com/problemset/problem/1000/C 2 3 C. Covered Points Count 4 5 time limit per test 6 7 3 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 You are given $n$ segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide. 22 23 Your task is the following: for every $k \in [1..n]$, calculate the number of points with integer coordinates such that the number of segments that cover these points equals $k$. A segment with endpoints $l_i$ and $r_i$ covers point $x$ if and only if $l_i \le x \le r_i$. 24 25 Input 26 27 The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of segments. 28 29 The next $n$ lines contain segments. The $i$-th line contains a pair of integers $l_i, r_i$ ($0 \le l_i \le r_i \le 10^{18}$) — the endpoints of the $i$-th segment. 30 31 Output 32 33 Print $n$ space separated integers $cnt_1, cnt_2, \dots, cnt_n$, where $cnt_i$ is equal to the number of points such that the number of segments that cover these points equals to $i$. 34 35 Examples 36 37 Input 38 39 ``` 40 3 41 0 3 42 1 3 43 3 8 44 ``` 45 46 Output 47 48 ``` 49 6 2 1 50 ``` 51 52 Input 53 54 ``` 55 3 56 1 3 57 2 4 58 5 7 59 ``` 60 61 Output 62 63 ``` 64 5 2 0 65 ``` 66 67 Note 68 69 The picture describing the first example: 70 71  72 73 Points with coordinates $[0, 4, 5, 6, 7, 8]$ are covered by one segment, points $[1, 2]$ are covered by two segments and point $[3]$ is covered by three segments. 74 75 The picture describing the second example: 76 77  78 79 Points $[1, 4, 5, 6, 7]$ are covered by one segment, points $[2, 3]$ are covered by two segments and there are no points covered by three segments.