A8290 | History
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.
Everybody knows that the World history encompasses exactly $n$ events: the $i$ -th event had continued from the year $a_{i}$ to the year $b_{i}$ inclusive ( $a_{i}<b_{i}$ ). Polycarpus easily learned the dates when each of $n$ events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event $j$ includes an event $i$ if $a_{j}<a_{i}$ and $b_{i}<b_{j}$ . Your task is simpler: find the number of events that are included in some other event.
Everybody knows that the World history encompasses exactly $n$ events: the $i$ -th event had continued from the year $a_{i}$ to the year $b_{i}$ inclusive ( $a_{i}<b_{i}$ ). Polycarpus easily learned the dates when each of $n$ events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event $j$ includes an event $i$ if $a_{j}<a_{i}$ and $b_{i}<b_{j}$ . Your task is simpler: find the number of events that are included in some other event.
输入格式
The first input line contains integer $n$ ( $1<=n<=10^{5}$ ) which represents the number of events. Next $n$ lines contain descriptions of the historical events, one event per line. The $i+1$ line contains two integers $a_{i}$ and $b_{i}$ ( $1<=a_{i}<b_{i}<=10^{9}$ ) — the beginning and the end of the $i$ -th event. No two events start or finish in the same year, that is, $a_{i}≠a_{j},a_{i}≠b_{j},b_{i}≠a_{j},b_{i}≠b_{j}$ for all $i$ , $j$ (where $i≠j$ ). Events are given in arbitrary order.
输出格式
Print the only integer — the answer to the problem.
输入输出样例
输入 #1
5 1 10 2 9 3 8 4 7 5 6
输出 #1
4
输入 #2
5 1 100 2 50 51 99 52 98 10 60
输出 #2
4
输入 #3
1 1 1000000000
输出 #3
0
In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first.
In the second example all events except the first one are contained in the first.
In the third example only one event, so the answer is 0.
In the second example all events except the first one are contained in the first.
In the third example only one event, so the answer is 0.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted