A14379 | Gates to Another World
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
As mentioned previously William really likes playing video games. In one of his favorite games, the player character is in a universe where every planet is designated by a binary number from $0$ to $2^n - 1$ . On each planet, there are gates that allow the player to move from planet $i$ to planet $j$ if the binary representations of $i$ and $j$ differ in exactly one bit.
William wants to test you and see how you can handle processing the following queries in this game universe:
- Destroy planets with numbers from $l$ to $r$ inclusively. These planets cannot be moved to anymore.
- Figure out if it is possible to reach planet $b$ from planet $a$ using some number of planetary gates. It is guaranteed that the planets $a$ and $b$ are not destroyed.
William wants to test you and see how you can handle processing the following queries in this game universe:
- Destroy planets with numbers from $l$ to $r$ inclusively. These planets cannot be moved to anymore.
- Figure out if it is possible to reach planet $b$ from planet $a$ using some number of planetary gates. It is guaranteed that the planets $a$ and $b$ are not destroyed.
输入格式
The first line contains two integers $n$ , $m$ ( $1 \leq n \leq 50$ , $1 \leq m \leq 5 \cdot 10^4$ ), which are the number of bits in binary representation of each planets' designation and the number of queries, respectively.
Each of the next $m$ lines contains a query of two types:
block l r — query for destruction of planets with numbers from $l$ to $r$ inclusively ( $0 \le l \le r < 2^n$ ). It's guaranteed that no planet will be destroyed twice.
ask a b — query for reachability between planets $a$ and $b$ ( $0 \le a, b < 2^n$ ). It's guaranteed that planets $a$ and $b$ hasn't been destroyed yet.
Each of the next $m$ lines contains a query of two types:
block l r — query for destruction of planets with numbers from $l$ to $r$ inclusively ( $0 \le l \le r < 2^n$ ). It's guaranteed that no planet will be destroyed twice.
ask a b — query for reachability between planets $a$ and $b$ ( $0 \le a, b < 2^n$ ). It's guaranteed that planets $a$ and $b$ hasn't been destroyed yet.
输出格式
For each query of type ask you must output "1" in a new line, if it is possible to reach planet $b$ from planet $a$ and "0" otherwise (without quotation marks).
输入输出样例
输入 #1
3 3 ask 0 7 block 3 6 ask 0 7
输出 #1
1 0
输入 #2
6 10 block 12 26 ask 44 63 block 32 46 ask 1 54 block 27 30 ask 10 31 ask 11 31 ask 49 31 block 31 31 ask 2 51
输出 #2
1 1 0 0 1 0
The first example test can be visualized in the following way:
Response to a query ask 0 7 is positive.
Next after query block 3 6 the graph will look the following way (destroyed vertices are highlighted):
Response to a query ask 0 7 is negative, since any path from vertex $0$ to vertex $7$ must go through one of the destroyed vertices.
Response to a query ask 0 7 is positive.
Next after query block 3 6 the graph will look the following way (destroyed vertices are highlighted):
Response to a query ask 0 7 is negative, since any path from vertex $0$ to vertex $7$ must go through one of the destroyed vertices.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted