Union of Interval

AtCoder
IDabc256_d
Time2000ms
Memory256MB
Difficulty
For real numbers $L$ and $R$, let us denote by $[L,R)$ the set of real numbers greater than or equal to $L$ and less than $R$. Such a set is called a right half-open interval. You are given $N$ right half-open intervals $[L_i,R_i)$. Let $S$ be their union. Represent $S$ as a union of the minimum number of right half-open intervals. ## Constraints * $1 \leq N \leq 2\times 10^5$ * $1 \leq L_i \lt R_i \leq 2\times 10^5$ * All values in input are integers. ## Input Input is given from Standard Input in the following format: $N$ $L_1$ $R_1$ $\vdots$ $L_N$ $R_N$ [samples]
Samples
Input #1
3
10 20
20 30
40 50
Output #1
10 30
40 50

The union of the three right half-open intervals $[10,20),[20,30),[40,50)$ equals the union of two right half-open intervals $[10,30),[40,50)$.
Input #2
3
10 40
30 60
20 50
Output #2
10 60

The union of the three right half-open intervals $[10,40),[30,60),[20,50)$ equals the union of one right half-open interval $[10,60)$.
API Response (JSON)
{
  "problem": {
    "name": "Union of Interval",
    "description": {
      "content": "For real numbers $L$ and $R$, let us denote by $[L,R)$ the set of real numbers greater than or equal to $L$ and less than $R$. Such a set is called a right half-open interval. You are given $N$ right ",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc256_d"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "For real numbers $L$ and $R$, let us denote by $[L,R)$ the set of real numbers greater than or equal to $L$ and less than $R$. Such a set is called a right half-open interval.\nYou are given $N$ right ...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments