CF809D.Hitchhiking in the Baltic States
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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__id__i < x__id__i + 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.
列哈和诺拉决定去波罗的海国家旅行。正如上一题所知,列哈把车丢在了餐厅的停车场。不幸的是,向看守员求助并未帮这位黑客找回汽车,因此朋友们决定搭便车出行。
他们原计划总共访问 n 个城镇。然而,第 i 个城镇的景点仅在第 li 天至第 ri 天(含端点)对游客开放。
该怎么办呢?列哈提议:对每个城镇 i,选择一个他们将访问该城镇的具体日期,即任取一个整数 xi∈[li,ri]。随后,诺拉从所有城镇中选出一个子序列 id1,id2,…,idk,作为朋友们实际将要访问的城镇序列,要求该子序列满足两个条件:
- 城镇编号严格递增,即对所有 i=1,2,…,k−1,均有 idi<idi+1;
- 对应的访问日期也严格递增,即对所有 i=1,2,…,k−1,均有 xidi<xidi+1。
请帮助列哈和诺拉为每个城镇 i 选定访问日期 xi,并选定城镇子序列 id1,id2,…,idk,使得朋友们能够访问的城镇数量最大化。
你可以假设列哈和诺拉可以从任意一天开始他们的旅行。
输入格式
The first line contains a single integer n (1 ≤ n ≤ 3·105) 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 ≤ 109), denoting that sights in i-th town are open for visitors on any day
.
第一行包含一个整数 n(1≤n≤3⋅105),表示 Leha 和 Noora 计划访问的城镇数量。
接下来的 n 行中,第 i 行包含两个整数 li、ri(1≤li≤ri≤109),表示第 i 个城镇的景点在任意一天
对游客开放。
输出格式
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.
考虑第一个例子。
我们采用如下计划:第一天游览第二座城市的景点,第三天游览第三座城市的景点,第四天游览第五座城市的景点。这就是最优解。
输入解题思路,AI测评打分。不知道怎么写?