A12307 | Polycarp's New Job
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Polycarp has recently got himself a new job. He now earns so much that his old wallet can't even store all the money he has.
Berland bills somehow come in lots of different sizes. However, all of them are shaped as rectangles (possibly squares). All wallets are also produced in form of rectangles (possibly squares).
A bill $x \times y$ fits into some wallet $h \times w$ if either $x \le h$ and $y \le w$ or $y \le h$ and $x \le w$ . Bills can overlap with each other in a wallet and an infinite amount of bills can fit into a wallet. That implies that all the bills Polycarp currently have fit into a wallet if every single one of them fits into it independently of the others.
Now you are asked to perform the queries of two types:
1. $+~x~y$ — Polycarp earns a bill of size $x \times y$ ;
2. $?~h~w$ — Polycarp wants to check if all the bills he has earned to this moment fit into a wallet of size $h \times w$ .
It is guaranteed that there is at least one query of type $1$ before the first query of type $2$ and that there is at least one query of type $2$ in the input data.
For each query of type $2$ print "YES" if all the bills he has earned to this moment fit into a wallet of given size. Print "NO" otherwise.
Berland bills somehow come in lots of different sizes. However, all of them are shaped as rectangles (possibly squares). All wallets are also produced in form of rectangles (possibly squares).
A bill $x \times y$ fits into some wallet $h \times w$ if either $x \le h$ and $y \le w$ or $y \le h$ and $x \le w$ . Bills can overlap with each other in a wallet and an infinite amount of bills can fit into a wallet. That implies that all the bills Polycarp currently have fit into a wallet if every single one of them fits into it independently of the others.
Now you are asked to perform the queries of two types:
1. $+~x~y$ — Polycarp earns a bill of size $x \times y$ ;
2. $?~h~w$ — Polycarp wants to check if all the bills he has earned to this moment fit into a wallet of size $h \times w$ .
It is guaranteed that there is at least one query of type $1$ before the first query of type $2$ and that there is at least one query of type $2$ in the input data.
For each query of type $2$ print "YES" if all the bills he has earned to this moment fit into a wallet of given size. Print "NO" otherwise.
输入格式
The first line contains a single integer $n$ ( $2 \le n \le 5 \cdot 10^5$ ) — the number of queries.
Each of the next $n$ lines contains a query of one of these two types:
1. $+~x~y$ ( $1 \le x, y \le 10^9$ ) — Polycarp earns a bill of size $x \times y$ ;
2. $?~h~w$ ( $1 \le h, w \le 10^9$ ) — Polycarp wants to check if all the bills he has earned to this moment fit into a wallet of size $h \times w$ .
It is guaranteed that there is at least one query of type $1$ before the first query of type $2$ and that there is at least one query of type $2$ in the input data.
Each of the next $n$ lines contains a query of one of these two types:
1. $+~x~y$ ( $1 \le x, y \le 10^9$ ) — Polycarp earns a bill of size $x \times y$ ;
2. $?~h~w$ ( $1 \le h, w \le 10^9$ ) — Polycarp wants to check if all the bills he has earned to this moment fit into a wallet of size $h \times w$ .
It is guaranteed that there is at least one query of type $1$ before the first query of type $2$ and that there is at least one query of type $2$ in the input data.
输出格式
For each query of type $2$ print "YES" if all the bills he has earned to this moment fit into a wallet of given size. Print "NO" otherwise.
输入输出样例
输入 #1
9 + 3 2 + 2 3 ? 1 20 ? 3 3 ? 2 3 + 1 5 ? 10 10 ? 1 5 + 1 1
输出 #1
NO YES YES YES NO
The queries of type $2$ of the example:
1. Neither bill fits;
2. Both bills fit (just checking that you got that bills can overlap);
3. Both bills fit (both bills are actually the same);
4. All bills fit (too much of free space in a wallet is not a problem);
5. Only bill $1 \times 5$ fit (all the others don't, thus it's "NO").
1. Neither bill fits;
2. Both bills fit (just checking that you got that bills can overlap);
3. Both bills fit (both bills are actually the same);
4. All bills fit (too much of free space in a wallet is not a problem);
5. Only bill $1 \times 5$ fit (all the others don't, thus it's "NO").
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted