Deltix Round, Summer 2021 (open for everyone, rated, Div. 1 + Div. 2)
G
Gates to Another World
Codeforces
3300
原题
← FH →
翻译中…

image

翻译中…

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.
翻译中…

Input

翻译中…

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 \lt 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 \lt 2^n$). It's guaranteed that planets $a$ and $b$ hasn't been destroyed yet.

翻译中…

Output

翻译中…

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).

翻译中…

Note

翻译中…

The first example test can be visualized in the following way:

翻译中…

image

翻译中…

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):

翻译中…

image

翻译中…

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.

翻译中…

样例

Input #1
3 3
ask 0 7
block 3 6
ask 0 7
Output #1
1
0
InputCopy OutputCopy
Input #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
Output #2
1
1
0
0
1
0
InputCopy OutputCopy
题目信息
题号
1556G
时间限制
4 s
内存限制
1024 MB
标签
位运算
数据结构
并查集
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。