A10639 | Road to Home
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Once Danil the student was returning home from tram stop lately by straight road of length $L$ . The stop is located at the point $x=0$ , but the Danil's home — at the point $x=L$ . Danil goes from $x=0$ to $x=L$ with a constant speed and does not change direction of movement.
There are $n$ street lights at the road, each of which lights some continuous segment of the road. All of the $n$ lightened segments do not share common points.
Danil loves to sing, thus he wants to sing his favourite song over and over again during his walk. As soon as non-lightened segments of the road scare him, he sings only when he goes through the lightened segments.
Danil passes distance $p$ while performing his favourite song once. Danil can't start another performance if the segment passed while performing is not fully lightened. Moreover, if Danil has taken a pause between two performances, he is not performing while not having passed a segment of length at least $t$ . Formally,
1. Danil can start single performance at a point $x$ only if every point of segment $[x,x+p]$ is lightened;
2. If Danil has finished performing at a point $x+p$ , then the next performance can be started only at a point $y$ such that $y=x+p$ or $y>=x+p+t$ satisfying the statement under the point $1$ .
Blue half-circles denote performances. Please note that just after Danil has taken a pause in performing, he has not sang for a path of length of at least $t$ .Determine how many times Danil can perform his favourite song during his walk from $x=0$ to $x=L$ .
Please note that Danil does not break a single performance, thus, started singing another time, he finishes singing when having a segment of length of $p$ passed from the performance start point.
There are $n$ street lights at the road, each of which lights some continuous segment of the road. All of the $n$ lightened segments do not share common points.
Danil loves to sing, thus he wants to sing his favourite song over and over again during his walk. As soon as non-lightened segments of the road scare him, he sings only when he goes through the lightened segments.
Danil passes distance $p$ while performing his favourite song once. Danil can't start another performance if the segment passed while performing is not fully lightened. Moreover, if Danil has taken a pause between two performances, he is not performing while not having passed a segment of length at least $t$ . Formally,
1. Danil can start single performance at a point $x$ only if every point of segment $[x,x+p]$ is lightened;
2. If Danil has finished performing at a point $x+p$ , then the next performance can be started only at a point $y$ such that $y=x+p$ or $y>=x+p+t$ satisfying the statement under the point $1$ .
Blue half-circles denote performances. Please note that just after Danil has taken a pause in performing, he has not sang for a path of length of at least $t$ .Determine how many times Danil can perform his favourite song during his walk from $x=0$ to $x=L$ .
Please note that Danil does not break a single performance, thus, started singing another time, he finishes singing when having a segment of length of $p$ passed from the performance start point.
输入格式
The first line of the input contains four integers $L$ , $n$ , $p$ and $t$ ( $1<=L<=10^{9}$ , $0<=n<=100000$ , $1<=p<=10^{9}$ , $1<=t<=10^{9}$ ) — the length of the Danil's path, the number of street lights at the road, the distance Danil passes while doing single performance and the minimum distance of pause respectively.
The next $n$ lines describe segments lightened by street lights. $i$ -th of them contains two integers $l_{i},r_{i}$ ( $0<=l_{i}<r_{i}<=L$ ) — the endpoints of the segment lightened by $i$ -th street light. It is guaranteed that no two segments are intersecting, nesting, or touching each other. The segments are given in the order from left to right.
The next $n$ lines describe segments lightened by street lights. $i$ -th of them contains two integers $l_{i},r_{i}$ ( $0<=l_{i}<r_{i}<=L$ ) — the endpoints of the segment lightened by $i$ -th street light. It is guaranteed that no two segments are intersecting, nesting, or touching each other. The segments are given in the order from left to right.
输出格式
Print the only integer — the maximum number of performances of Danil's favourite song on the path from $x=0$ to $x=L$ .
输入输出样例
输入 #1
17 2 2 6 0 9 13 17
输出 #1
5
输入 #2
12 2 2 2 0 5 6 11
输出 #2
4
输入 #3
12 2 2 4 0 5 6 11
输出 #3
3
The first sample case is just about corresponding to the picture from the statement.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted