CF558D.Guess Your Way Out! II

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Amr bought a new video game "Guess Your Way Out! II". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height h. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node.

Let's index all the nodes of the tree such that

  • The root is number 1
  • Each internal node i (i ≤ 2_h_ - 1 - 1) will have a left child with index = 2_i_ and a right child with index = 2_i_ + 1

The level of a node is defined as 1 for a root, or 1 + level of parent of the node otherwise. The vertices of the level h are called leaves. The exit to the maze is located at some leaf node n, the player doesn't know where the exit is so he has to guess his way out!

In the new version of the game the player is allowed to ask questions on the format "Does the ancestor(exit, i) node number belong to the range [L, R]?". Here ancestor(v, i) is the ancestor of a node v that located in the level i. The game will answer with "Yes" or "No" only. The game is designed such that it doesn't always answer correctly, and sometimes it cheats to confuse the player!.

Amr asked a lot of questions and got confused by all these answers, so he asked you to help him. Given the questions and its answers, can you identify whether the game is telling contradictory information or not? If the information is not contradictory and the exit node can be determined uniquely, output its number. If the information is not contradictory, but the exit node isn't defined uniquely, output that the number of questions is not sufficient. Otherwise output that the information is contradictory.

Amr 购买了一款新视频游戏《猜猜你的出路!II》。游戏目标是找到一个形如高度为 hh 的完美二叉树的迷宫的出口。玩家初始时站在树的根节点,而迷宫出口位于某个叶节点上。

我们对树的所有节点进行如下编号:

  • 根节点编号为 11;
  • 每个内部节点 ii(满足 i≤2h−1−1i \leq 2^{h-1} - 1)的左子节点编号为 2i2i,右子节点编号为 2i+12i + 1。

节点的层号(level)定义如下:根节点的层号为 11;其余任意节点的层号为其父节点的层号加 11。所有层号为 hh 的节点称为叶节点(leaves)。迷宫出口位于某个叶节点 nn 上;但玩家并不知道出口具体在哪个叶节点,因此他必须通过猜测来寻找出路!

在游戏的新版本中,玩家可以提出如下形式的问题:“节点 ancestor(exit, i)\text{ancestor}(\text{exit},\, i) 的编号是否属于区间 [L, R][L,\, R]?”其中 ancestor(v, i)\text{ancestor}(v,\, i) 表示节点 vv 在第 ii 层上的祖先节点。游戏仅回答“Yes”或“No”。但该游戏被特别设计为并非总是给出正确答案,有时它会故意撒谎以迷惑玩家!

Amr 提出了大量问题,却被这些答案搞得晕头转向,于是他请你帮忙。给定所有提问及其对应答案,你能否判断这些信息是否存在矛盾?若信息不矛盾且能唯一确定出口节点,则输出该节点编号;若信息不矛盾但无法唯一确定出口节点,则输出“提问数量不足”;否则输出“信息矛盾”。

输入格式

The first line contains two integers h, q (1 ≤ h ≤ 50, 0 ≤ q ≤ 105), the height of the tree and the number of questions respectively.

The next q lines will contain four integers each i, L, R, ans (1 ≤ i ≤ h, 2_i_ - 1 ≤ L ≤ R ≤ 2_i_ - 1, ), representing a question as described in the statement with its answer (ans = 1 if the answer is "Yes" and ans = 0 if the answer is "No").

第一行包含两个整数 hh 和 qq(1≤h≤501 \le h \le 50,0≤q≤1050 \le q \le 10^5),分别表示树的高度和问题的数量。

接下来的 qq 行每行包含四个整数 ii、LL、RR、ansans(1≤i≤h1 \le i \le h,2i−1≤L≤R≤2i−12^{i-1} \le L \le R \le 2^i - 1,),表示题目描述中的一个问题及其答案(若答案为“Yes”,则 ans=1ans = 1;若答案为“No”,则 ans=0ans = 0)。

输出格式

If the information provided by the game is contradictory output "Game cheated!" without the quotes.

Else if you can uniquely identify the exit to the maze output its index.

Otherwise output "Data not sufficient!" without the quotes.

如果游戏提供的信息自相矛盾,则输出“Game cheated!”(不含引号)。

否则,若能唯一确定迷宫的出口,则输出其索引。

否则,输出“Data not sufficient!”(不含引号)。

输入输出样例

  • 输入#1

    3 1
    3 4 6 0

    输出#1

    7
  • 输入#2

    4 3
    4 10 14 1
    3 6 6 0
    2 3 3 1

    输出#2

    14
  • 输入#3

    4 2
    3 4 6 1
    4 12 15 1

    输出#3

    Data not sufficient!
  • 输入#4

    4 2
    3 4 5 1
    2 3 3 1

    输出#4

    Game cheated!

说明/提示

Node u is an ancestor of node v if and only if

  • u is the same node as v,
  • u is the parent of node v,
  • or u is an ancestor of the parent of node v.

In the first sample test there are 4 leaf nodes 4, 5, 6, 7. The first question says that the node isn't in the range [4, 6] so the exit is node number 7.

In the second sample test there are 8 leaf nodes. After the first question the exit is in the range [10, 14]. After the second and the third questions only node number 14 is correct. Check the picture below to fully understand.

节点 uu 是节点 vv 的祖先,当且仅当满足以下条件之一:

  • uu 与 vv 是同一个节点;
  • uu 是节点 vv 的父节点;
  • uu 是节点 vv 的父节点的祖先。

在第一个样例测试中,有 4 个叶子节点:4、5、6、7。第一个问题指出出口节点不在区间 [4, 6][4,\,6] 内,因此出口节点为编号 7。

在第二个样例测试中,共有 8 个叶子节点。第一个问题之后,出口节点位于区间 [10, 14][10,\,14] 内;再经过第二和第三个问题后,唯一满足条件的节点是编号 14。请参见下方图片以全面理解。

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

首页