CF1556G.Gates to Another World

NOI/NOI+/CTSC

通过率:0%

时间限制:4.00s

内存限制:1024MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 00 to 2n−12^n - 1. On each planet, there are gates that allow the player to move from planet ii to planet jj if the binary representations of ii and jj 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 ll to rr inclusively. These planets cannot be moved to anymore.
  • Figure out if it is possible to reach planet bb from planet aa using some number of planetary gates. It is guaranteed that the planets aa and bb are not destroyed.

如前所述,威廉非常喜欢玩电子游戏。在他最喜爱的一款游戏中,玩家角色所处的宇宙中,每颗行星均用一个从 00 到 2n−12^n - 1 的二进制数标识。在每颗行星上,都设有传送门,允许玩家从行星 ii 移动到行星 jj,当且仅当 ii 与 jj 的二进制表示恰好有一位不同。

威廉想考验你,看你能否在这个游戏宇宙中高效处理以下两类查询:

  • 摧毁编号在区间 [l,r][l, r] 内(含端点)的所有行星。这些被摧毁的行星将不再可到达。
  • 判断是否能通过若干次行星传送门,从行星 aa 到达行星 bb。题目保证行星 aa 和 bb 均未被摧毁。

输入格式

The first line contains two integers nn, mm (1≤n≤501 \leq n \leq 50, 1≤m≤5⋅1041 \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 mm lines contains a query of two types:

block l r — query for destruction of planets with numbers from ll to rr inclusively (0≤l≤r<2n0 \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 aa and bb (0≤a,b<2n0 \le a, b \lt 2^n). It's guaranteed that planets aa and bb hasn't been destroyed yet.

第一行包含两个整数 nn 和 mm(1≤n≤501 \leq n \leq 50,1≤m≤5⋅1041 \leq m \leq 5 \cdot 10^4),分别表示每个行星编号的二进制表示的位数以及查询次数。

接下来的 mm 行,每行包含一种类型的查询:

block l r — 查询摧毁编号在 ll 到 rr(含端点)之间的所有行星(0≤l≤r<2n0 \le l \le r \lt 2^n)。保证任意行星不会被摧毁两次。

ask a b — 查询行星 aa 与行星 bb 之间是否可达(0≤a,b<2n0 \le a, b \lt 2^n)。保证行星 aa 和 bb 尚未被摧毁。

输出格式

For each query of type ask you must output "1" in a new line, if it is possible to reach planet bb from planet aa and "0" otherwise (without quotation marks).

对于每个类型为 ask 的查询,如果可以从星球 aa 到达星球 bb,则在新的一行输出 1,否则输出 0(不带引号)。

输入输出样例

  • 输入#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 00 to vertex 77 must go through one of the destroyed vertices.

第一个示例测试可可视化为如下所示:

对查询 ask 0 7 的回答为“是”。

在执行查询块 3 6 后,图将变为如下所示(被摧毁的顶点已高亮显示):

此时对查询 ask 0 7 的回答为“否”,因为从顶点 00 到顶点 77 的任意路径都必须经过至少一个被摧毁的顶点。

输入解题思路,AI测评打分。不知道怎么写?

首页