Hitchhiking in the Baltic States

题意翻译

给出 $n$ 个区间 $[l_i,r_i]$ 和 $n$ 个未知数 $a_1,a_2,\dots,a_n$,现在你要确定这 $n$ 个数,使得 $a_i\in[l_i,r_i]$,并且这个序列的最长严格上升子序列尽可能大,求这个最大值。 $1 \leq n\leq 3\times 10^5$,$1 \leq l_i,r_i\leq 10^9$。

题目描述

Leha and Noora decided to go on a trip in the Baltic States. As you know from the previous problem, Leha has lost his car on the parking of the restaurant. Unfortunately, requests to the watchman didn't helped hacker find the car, so friends decided to go hitchhiking. In total, they intended to visit $ n $ towns. However it turned out that sights in $ i $ -th town are open for visitors only on days from $ l_{i} $ to $ r_{i} $ . What to do? Leha proposed to choose for each town $ i $ a day, when they will visit this town, i.e any integer $ x_{i} $ in interval $ [l_{i},r_{i}] $ . After that Noora choses some subsequence of towns $ id_{1},id_{2},...,id_{k} $ , which friends are going to visit, that at first they are strictly increasing, i.e $ id_{i}<id_{i+1} $ is for all integers $ i $ from $ 1 $ to $ k-1 $ , but also the dates of the friends visits are strictly increasing, i.e $ x_{idi}<x_{idi+1} $ is true for all integers $ i $ from $ 1 $ to $ k-1 $ . Please help Leha and Noora in choosing such $ x_{i} $ for each town $ i $ , and such subsequence of towns $ id_{1},id_{2},...,id_{k} $ , so that friends can visit maximal number of towns. You may assume, that Leha and Noora can start the trip any day.

输入输出格式

输入格式


The first line contains a single integer $ n $ ( $ 1<=n<=3·10^{5} $ ) denoting the number of towns Leha and Noora intended to visit. Each line $ i $ of the $ n $ subsequent lines contains two integers $ l_{i} $ , $ r_{i} $ $ (1<=l_{i}<=r_{i}<=10^{9}) $ , denoting that sights in $ i $ -th town are open for visitors on any day ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF809D/67e7c15a830b4bf2b41222394fc99591b0cfcff8.png).

输出格式


Print a single integer denoting the maximal number of towns, that Leha and Noora can visit.

输入输出样例

输入样例 #1

5
6 6
1 2
3 4
2 2
1 4

输出样例 #1

3

说明

Consider the first example. Let's take this plan: let's visit the sight in the second town on the first day, in the third town on the third day and in the fifth town on the fourth. That's would be the optimal answer.