A16175 | In Love
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Initially, you have an empty multiset of segments. You need to process $q$ operations of two types:
- $+$ $l$ $r$ — Add the segment $(l, r)$ to the multiset,
- $-$ $l$ $r$ — Remove exactly one segment $(l, r)$ from the multiset. It is guaranteed that this segment exists in the multiset.
After each operation, you need to determine if there exists a pair of segments in the multiset that do not intersect. A pair of segments $(l, r)$ and $(a, b)$ do not intersect if there does not exist a point $x$ such that $l \leq x \leq r$ and $a \leq x \leq b$ .
- $+$ $l$ $r$ — Add the segment $(l, r)$ to the multiset,
- $-$ $l$ $r$ — Remove exactly one segment $(l, r)$ from the multiset. It is guaranteed that this segment exists in the multiset.
After each operation, you need to determine if there exists a pair of segments in the multiset that do not intersect. A pair of segments $(l, r)$ and $(a, b)$ do not intersect if there does not exist a point $x$ such that $l \leq x \leq r$ and $a \leq x \leq b$ .
输入格式
The first line of each test case contains an integer $q$ ( $1 \leq q \leq 10^5$ ) — the number of operations.
The next $q$ lines describe two types of operations. If it is an addition operation, it is given in the format $+$ $l$ $r$ . If it is a deletion operation, it is given in the format $-$ $l$ $r$ ( $1 \leq l \leq r \leq 10^9$ ).
The next $q$ lines describe two types of operations. If it is an addition operation, it is given in the format $+$ $l$ $r$ . If it is a deletion operation, it is given in the format $-$ $l$ $r$ ( $1 \leq l \leq r \leq 10^9$ ).
输出格式
After each operation, print "YES" if there exists a pair of segments in the multiset that do not intersect, and "NO" otherwise.
You can print the answer in any case (uppercase or lowercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive answers.
You can print the answer in any case (uppercase or lowercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive answers.
输入输出样例
输入 #1
12 + 1 2 + 3 4 + 2 3 + 2 2 + 3 4 - 3 4 - 3 4 - 1 2 + 3 4 - 2 2 - 2 3 - 3 4
输出 #1
NO YES YES YES YES YES NO NO YES NO NO NO
In the example, after the second, third, fourth, and fifth operations, there exists a pair of segments $(1, 2)$ and $(3, 4)$ that do not intersect.
Then we remove exactly one segment $(3, 4)$ , and by that time we had two segments. Therefore, the answer after this operation also exists.
Then we remove exactly one segment $(3, 4)$ , and by that time we had two segments. Therefore, the answer after this operation also exists.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted