题意是这样:

一颗高为h的完美二叉树,根节点为1,标号为i的结点的左右儿子标号分别为2*i,2*i+1

q次操作,i,l,r,ans

ans==0时,代表在第i层,出口的祖先不在[l,r]之间

ans==1时,代表在第i层,出口的祖先在[l,r]之间

若出口(出口一定在叶子上)唯一则输出它的标号,不唯一或无解则分别输出对应的串

我想到的做法很显然,把所有ans==1的子树的叶子区间全部算出来,遍历所有区间,

不断做交集,若不出现交集则无解,于是结果必然是得到一个唯一区间x,出口一定在这里面。

把所有ans==0的子树的叶子区间全部算出来,遍历所有区间,x不断删除与他们相交的部分,

很显然若是最终x的区间只有一个数,那么出口唯一就是这个数,否则有多个解

想到这个很简单。。编码有点麻烦……不过慢慢分治还是能够写对的

#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<climits>
#include<list>
#include<iomanip>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
struct Itv
{ll l,r;Itv(){}Itv(ll l,ll r){this->l=l;this->r=r;}Itv its(Itv one){if(one.r<l||one.l>r)return Itv(1,0);return Itv(max(one.l,l),min(one.r,r));}
};
ll fac[60]={1};
Itv cg(ll val,int lv,int h)
{return Itv(fac[h-lv]*val,fac[h-lv]*val+fac[h-lv]-1);
}
bool cmp(Itv one,Itv two)
{return one.l<two.l;
}
int main()
{int h,q;cin>>h>>q;for(int i=1;i<=h;i++)fac[i]=fac[i-1]*2;vector<Itv>itv[2];while(q--){int i,ans;ll l,r;cin>>i>>l>>r>>ans;itv[ans].push_back(Itv(cg(l,i,h).l,cg(r,i,h).r));}int n=itv[0].size(),m=itv[1].size();for(int i=1;i<m;i++){itv[1][0]=itv[1][0].its(itv[1][i]);if(itv[1][0].l>itv[1][0].r){puts("Game cheated!");return 0;}}Itv t;if(m!=0)t=itv[1][0];elset=Itv(cg(1,1,h).l,cg(1,1,h).r);sort(itv[0].begin(),itv[0].end(),cmp);ll ans=-1;for(int i=0;i<n;i++){Itv t1=t.its(itv[0][i]);if(t1.l>t1.r)continue;if(t1.l==t.l&&t1.r==t.r){if(ans==-1)puts("Game cheated!");elsecout<<ans;return 0;}if(t1.l-t.l>1){puts("Data not sufficient!");return 0;}if(t1.l-t.l==1){if(ans==-1){ans=t.l;if(t.r==t1.r){cout<<ans;return 0;}}else{puts("Data not sufficient!");return 0;}}t.l=t1.r+1;}if(ans==-1){if(t.l==t.r)cout<<t.l;elseputs("Data not sufficient!");}elseputs("Data not sufficient!");
}
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 ≤ 2h - 1 - 1) will have a left child with index = 2i and a right child with index = 2i + 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.

Input

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, 2i - 1 ≤ L ≤ R ≤ 2i - 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").

Output

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.

Sample test(s)
input
3 1
3 4 6 0

output
7

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

output
14

input
4 2
3 4 6 1
4 12 15 1

output
Data not sufficient!

input
4 2
3 4 5 1
2 3 3 1

output
Game cheated!

Note

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.

codeforces 558 D Guess Your Way Out! II相关推荐

  1. Codeforces 558(C、D、E)总结

    558C 题意:给你n个数,可对每一个数进行操作(乘2或者除以2).求最少的操作使得全部的数都相等. 思路 : dp[ t ] 表示全部的数转化到 t 所需的最少操作, vis[ t ] 表示有多少数 ...

  2. Codeforces Round #700 (Div. 2) D2 Painting the Array II(最通俗易懂的贪心策略讲解)看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 整场比赛的A ~ E 6题全,全部题目超高质量题解链接: Codeforces Round #700 ...

  3. CodeForces - 1480D2 Painting the Array II(dp)

    题目链接:点击查看 题目大意:给出一个长度为 nnn 的序列,现在要求拆分成两个子序列,使得两个子序列的贡献之和最 小.对于一个序列的贡献就是,去掉相邻且相同的字母后的长度,即 ∑i=1n[a[i]! ...

  4. 暴力 Codeforces Round #183 (Div. 2) A. Pythagorean Theorem II

    题目传送门 1 /* 2 暴力:O (n^2) 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <c ...

  5. Codeforces Gym101257F:Islands II(求割点+思维)

    http://codeforces.com/gym/101257/problem/F 题意:给出一个n*m的地图,上面相同数字的代表一个国家,问对于每个国家有多少个国家在它内部(即被包围).例如第一个 ...

  6. Codeforces Round #450 (Div. 2)D. Unusual Sequences[数论][组合数学][dp II]

    题目:http://codeforces.com/contest/900/problem/D 题意:找到加和为m的且gcd为n的数列种类数 分析:可以转化为求gcd为1的加和为m/n的种类数,假设有m ...

  7. Codeforces Round #700 (Div. 2) A ~ E ,6题全,超高质量良心题解【每日亿题】2021/2/8

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A - Yet Another String Game B - The Great Hero C ...

  8. Codeforces Round #193 (Div. 2)

    题目地址: http://codeforces.com/contest/332 第一题:题目又臭又长,读了好长时间才读懂. n个人,你是0号,从0开始到n-1循环做动作,只要你前面三个人动作一样,你就 ...

  9. 暴力 + 贪心 --- Codeforces 558C : Amr and Chemistry

    C. Amr and Chemistry Problem's Link: http://codeforces.com/problemset/problem/558/C Mean: 给出n个数,让你通过 ...

  10. codeforces 954C

    codeforces 954C C. Matrix Walk introduction 一个x行y列矩形的矩形,每个格子的从左到右,从上到下编号.然后给出一条路径,确定x和y的值,使得这条路径成立. ...

最新文章

  1. Java经典面试题详解:springboot文件下载大小限制
  2. 内核知识第九讲,32位下的分页管理,36位下的分页管理.以及64位下的分页管理
  3. 揭开雷达的面纱(科普) 发射机
  4. 国防科技大学计算机学院少将,国防科技大学新任副校长兼教育长晋升少将,前任是计算机权威专家...
  5. Delphi TreeView失去焦点也选中
  6. 49. 模型层 --- dao 层
  7. jvisualVm用法
  8. java移位运算符有哪些_java中有三种移位运算符
  9. mockito验证参数_Mockito验证
  10. 车辆路径问题(VRP)初探
  11. 正式开始撰写《产品大师》,经验来自点滴的积累
  12. 排序算法——选择排序
  13. PET不干胶标签发展趋势
  14. 学习QT之图形视图实例#-飞舞的蝴蝶
  15. 数字联接新动能 | 专访亿联IT总监赖志豪:AI是亿联未来数字化建设的方向
  16. Android - BlueTooth BLE 之 Central 与 Peripheral
  17. WordPress建站教程 从零开始服务器搭建网站超详细
  18. 图片映射(HTML map标签)这么拽,小伙伴们都知道吗?
  19. jQuery Mobile 移动开发中的日期插件Mobiscroll 2.3 使用说明
  20. input输入框的限制输入

热门文章

  1. 怎么搜索代码里的所有中文汉字
  2. 3.深入了解listen函数
  3. MSP430的AD7705驱动程序
  4. FMS3.5的安装使用
  5. provisional headers are shown解决办法
  6. “快手极速版”的模拟器多开方法
  7. 安装nodejs时:The error code is 2503.
  8. 大学生计算机自我鉴定500字,大学生自我鉴定500字
  9. 调频连续波雷达(FMCW)测距/测速原理
  10. 计算机农林科学类sci期刊,农林科学类sci期刊有哪些