C. Covered Points Count

Codeforces
IDCF1000C
Time3000ms
Memory256MB
Difficulty
data structuresimplementationsortings
English · Original
Chinese · Translation
Formal · Original
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. 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$. ## Input The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of segments. 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. ## Output 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$. [samples] ## Note The picture describing the first example: ![image](https://espresso.codeforces.com/b3d344391aaf4b5f28e61d5120f885c1bdfa2449.png) 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. The picture describing the second example: ![image](https://espresso.codeforces.com/c76c8c48121e90f23f1bd1fd7326deba7278dccf.png) 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.
给定数轴上的 $n$ 个线段;每个线段的端点坐标均为整数。某些线段可能退化为点。线段之间可以相交、嵌套甚至重合。 你的任务如下:对于每个 $k \in [1..n]$,计算满足“恰好被 $k$ 个线段覆盖”的整数坐标点的个数。一个端点为 $l_i$ 和 $r_i$ 的线段覆盖点 $x$,当且仅当 $l_i \leq x \leq r_i$。 输入的第一行包含一个整数 $n$($1 \leq n \leq 2 \cdot 10^5$)——线段的数量。 接下来的 $n$ 行每行包含一个线段。第 $i$ 行包含一对整数 $l_i, r_i$($0 \leq l_i \leq r_i \leq 10^{18}$)——第 $i$ 个线段的端点。 请输出 $n$ 个用空格分隔的整数 $cnt_1, cnt_2, \dots, cnt_n$,其中 $cnt_i$ 表示恰好被 $i$ 个线段覆盖的整数点的个数。 第一个示例的图示: 坐标为 $[0, 4, 5, 6, 7, 8]$ 的点被一个线段覆盖,坐标为 $[1, 2]$ 的点被两个线段覆盖,坐标为 $[3]$ 的点被三个线段覆盖。 第二个示例的图示: 坐标为 $[1, 4, 5, 6, 7]$ 的点被一个线段覆盖,坐标为 $[2, 3]$ 的点被两个线段覆盖,没有点被三个线段覆盖。 ## Input 输入的第一行包含一个整数 $n$($1 \leq n \leq 2 \cdot 10^5$)——线段的数量。接下来的 $n$ 行每行包含一个线段。第 $i$ 行包含一对整数 $l_i, r_i$($0 \leq l_i \leq r_i \leq 10^{18}$)——第 $i$ 个线段的端点。 ## Output 请输出 $n$ 个用空格分隔的整数 $cnt_1, cnt_2, \dots, cnt_n$,其中 $cnt_i$ 表示恰好被 $i$ 个线段覆盖的整数点的个数。 [samples] ## Note 第一个示例的图示:坐标为 $[0, 4, 5, 6, 7, 8]$ 的点被一个线段覆盖,坐标为 $[1, 2]$ 的点被两个线段覆盖,坐标为 $[3]$ 的点被三个线段覆盖。 第二个示例的图示:坐标为 $[1, 4, 5, 6, 7]$ 的点被一个线段覆盖,坐标为 $[2, 3]$ 的点被两个线段覆盖,没有点被三个线段覆盖。
**Definitions** Let $ n \in \mathbb{Z}^+ $ be the number of segments. For each $ i \in \{1, \dots, n\} $, let $ [l_i, r_i] $ be a closed integer interval with $ l_i, r_i \in \mathbb{Z} $, $ 0 \le l_i \le r_i \le 10^{18} $. Let $ \mathcal{S} = \{ [l_i, r_i] \mid i = 1, \dots, n \} $ be the set of segments. For any integer point $ x \in \mathbb{Z} $, define the coverage count: $$ c(x) = \left| \left\{ i \in \{1, \dots, n\} \mid l_i \le x \le r_i \right\} \right| $$ For each $ k \in \{1, \dots, n\} $, define: $$ \text{cnt}_k = \left| \left\{ x \in \mathbb{Z} \mid c(x) = k \right\} \right| $$ **Constraints** 1. $ 1 \le n \le 2 \cdot 10^5 $ 2. For all $ i \in \{1, \dots, n\} $: $ 0 \le l_i \le r_i \le 10^{18} $ **Objective** Compute the vector $ (\text{cnt}_1, \text{cnt}_2, \dots, \text{cnt}_n) $.
Samples
Input #1
3
0 3
1 3
3 8
Output #1
6 2 1
Input #2
3
1 3
2 4
5 7
Output #2
5 2 0
API Response (JSON)
{
  "problem": {
    "name": "C. Covered Points Count",
    "description": {
      "content": "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 ea",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 3000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF1000C"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "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 ea...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "给定数轴上的 $n$ 个线段;每个线段的端点坐标均为整数。某些线段可能退化为点。线段之间可以相交、嵌套甚至重合。\n\n你的任务如下:对于每个 $k \\in [1..n]$,计算满足“恰好被 $k$ 个线段覆盖”的整数坐标点的个数。一个端点为 $l_i$ 和 $r_i$ 的线段覆盖点 $x$,当且仅当 $l_i \\leq x \\leq r_i$。\n\n输入的第一行包含一个整数 $n$($1 \\leq n...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z}^+ $ be the number of segments.  \nFor each $ i \\in \\{1, \\dots, n\\} $, let $ [l_i, r_i] $ be a closed integer interval with $ l_i, r_i \\in \\mathbb{Z} $, $ 0 \\le ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments