LIS 2

AtCoder
IDarc159_d
Time2500ms
Memory256MB
Difficulty
We have a sequence $X$, which is initially empty. Takahashi has performed the following operation for $i=1,2,\ldots,N$ in this order. * Append $l_i,l_i+1,\ldots,r_i$ in this order to the end of $X$. Find the greatest length of a strictly increasing subsequence of the final $X$. ## Constraints * $1 \leq N \leq 2 \times 10^5$ * $1 \leq l_i \leq r_i \leq 10^9$ * All values in the input are integers. ## Input The input is given from Standard Input in the following format: $N$ $l_1$ $r_1$ $\vdots$ $l_{N}$ $r_{N}$ [samples]
Samples
Input #1
4
1 1
2 4
10 11
7 10
Output #1
8

The final $X$ is $(1,2,3,4,10,11,7,8,9,10)$.  
The $1$\-st, $2$\-nd, $3$\-rd, $4$\-th, $7$\-th, $8$\-th, $9$\-th, and $10$\-th elements form a strictly increasing subsequence with the greatest length.
Input #2
4
1 1
1 1
1 1
1 1
Output #2
1

The final $X$ is $(1,1,1,1)$.
Input #3
1
1 1000000000
Output #3
1000000000
API Response (JSON)
{
  "problem": {
    "name": "LIS 2",
    "description": {
      "content": "We have a sequence $X$, which is initially empty.   Takahashi has performed the following operation for $i=1,2,\\ldots,N$ in this order. *   Append $l_i,l_i+1,\\ldots,r_i$ in this order to the end of $",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2500,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc159_d"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "We have a sequence $X$, which is initially empty.  \nTakahashi has performed the following operation for $i=1,2,\\ldots,N$ in this order.\n\n*   Append $l_i,l_i+1,\\ldots,r_i$ in this order to the end of $...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments