A9167 | Ping-Pong
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
In this problem at each moment you have a set of intervals. You can move from interval $(a,b)$ from our set to interval $(c,d)$ from our set if and only if $c
< a < d$ or $c < b < d$ . Also there is a path from interval $I_{1}$ from our set to interval $I_{2}$ from our set if there is a sequence of successive moves starting from $I_{1}$ so that we can reach $I_{2}$ .
Your program should handle the queries of the following two types:
1. "1 x y" $(x<y)$ — add the new interval $(x,y)$ to the set of intervals. The length of the new interval is guaranteed to be strictly greater than all the previous intervals.
2. "2 a b" $(a≠b)$ — answer the question: is there a path from $a$ -th (one-based) added interval to $b$ -th (one-based) added interval?
Answer all the queries. Note, that initially you have an empty set of intervals.
< a < d$ or $c < b < d$ . Also there is a path from interval $I_{1}$ from our set to interval $I_{2}$ from our set if there is a sequence of successive moves starting from $I_{1}$ so that we can reach $I_{2}$ .
Your program should handle the queries of the following two types:
1. "1 x y" $(x<y)$ — add the new interval $(x,y)$ to the set of intervals. The length of the new interval is guaranteed to be strictly greater than all the previous intervals.
2. "2 a b" $(a≠b)$ — answer the question: is there a path from $a$ -th (one-based) added interval to $b$ -th (one-based) added interval?
Answer all the queries. Note, that initially you have an empty set of intervals.
输入格式
The first line of the input contains integer $n$ denoting the number of queries, $(1 \leq n \leq 10^{5})$ . Each of the following lines contains a query as described above. All numbers in the input are integers and don't exceed $10^{9}$ by their absolute value.
It's guaranteed that all queries are correct.
It's guaranteed that all queries are correct.
输出格式
For each query of the second type print "YES" or "NO" on a separate line depending on the answer.
输入输出样例
输入 #1
5 1 1 5 1 5 11 2 1 2 1 2 9 2 1 2
输出 #1
NO YES
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted