题目链接

题意:

给出n和q

表示有一棵深度为n的全然二叉树。叶子节点中有恰好一个点是出口 主角从根往下走。但不知道出口在哪里,但主角会获得q个提示。
 像这样标号

q个提示 格式: deep [l, r] ok

 表示 深度为deep 时, 出口(可能在) (一定不在)[l,r]区间 
ok=1表示 是可能在 ok=0一定不在

目标:

若依据提示能找到出口则输出叶子节点下标,有多个可能的出口则输出data not sufficient。若给出的提示互相矛盾输出 Game cheatde

思路:

首先把全部提示的区间都映射到叶子节点上

先把一定不在的问题转成2个一定存在的提示。

那么显然每一个提示里都包括了出口。所以我们查询一下哪个点是被q个区间覆盖了,则这个点就是出口。

#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <cstdio>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#include <cstring>
#include <cmath>
#include <set>
#include <vector>
using namespace std;
template <class T>
inline bool rd(T &ret) {
char c; int sgn;
if (c = getchar(), c == EOF) return 0;
while (c != '-' && (c<'0' || c>'9')) c = getchar();
sgn = (c == '-') ? -1 : 1;
ret = (c == '-') ? 0 : (c - '0');
while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');
ret *= sgn;
return 1;
}
template <class T>
inline void pt(T x) {
if (x <0) {
putchar('-');
x = -x;
}
if (x>9) pt(x / 10);
putchar(x % 10 + '0');
}
typedef long long ll;
typedef pair<ll, ll> pii;
const int N = 500005;
const int inf = 1e9 + 10;
int n, q; ll L[55], R[55];
map<ll, int>mp;
int main() {
L[1] = R[1] = 1;
for (int i = 2; i <= 50; i++)L[i] = L[i - 1] << 1, R[i] = R[i - 1] << 1 | 1;
rd(n); rd(q);
if (q == 0) {
if (n == 1)puts("1");
else puts("Data not sufficient!");
return 0;
}
for (int i = 0, dep, ok; i < q; i++) {
ll l, r;
rd(dep); rd(l); rd(r); rd(ok);
while (dep < n) {
l <<= 1;
r = r << 1 | 1;
dep++;
}
if (ok)mp[l]++, mp[r + 1]--;
else {
mp[L[n]]++; mp[l]--;
mp[r + 1]++; mp[R[n]+1]--;
}
}
int sum = 0;
ll pre = -1, cnt = 0, ans = 0;
for (auto i : mp) {
sum += i.second;
if (pre != -1) {
cnt += i.first - pre;
ans = pre;
}
if (sum == q)pre = i.first;
else pre = -1;
}
if (cnt == 0)puts("Game cheated!");
else if (cnt > 1)puts("Data not sufficient!");
else pt(ans);
return 0;
}

codeforces 558D Guess Your Way Out! II 规律的更多相关文章

  1. 区间合并 --- Codeforces 558D : Gess Your Way Out ! II

    D. Guess Your Way Out! II Problem's Link: http://codeforces.com/problemset/problem/558/D Mean: 一棵满二叉 ...

  2. CodeForces 558D

     Guess Your Way Out! II Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  3. Codeforces Gym 100015A Another Rock-Paper-Scissors Problem 找规律

    Another Rock-Paper-Scissors Problem 题目连接: http://codeforces.com/gym/100015/attachments Description S ...

  4. Codeforces Gym 100114 A. Hanoi tower 找规律

    A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descript ...

  5. LightOJ1245 Harmonic Number (II) —— 规律

    题目链接:https://vjudge.net/problem/LightOJ-1245 1245 - Harmonic Number (II)    PDF (English) Statistics ...

  6. codeforces Gym 100418D BOPC 打表找规律,求逆元

    BOPCTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?c ...

  7. [CodeForces - 848B] Rooter's Song 思维 找规律

    大致题意: 有一个W*H的长方形,有n个人,分别站在X轴或Y轴,并沿直线向对面走,第i个人在ti的时刻出发,如果第i个人与第j个人相撞了 那么则交换两个人的运动方向,直到走到长方形边界停止,问最后每个 ...

  8. Codeforces Round #242 (Div. 2)C(找规律,异或运算)

    一看就是找规律的题.只要熟悉异或的性质,可以秒杀. 为了防止忘记异或的规则,可以把异或理解为半加运算:其运算法则相当于不带进位的二进制加法. 一些性质如下: 交换律: 结合律: 恒等律: 归零律: 典 ...

  9. codeforces 622D D. Optimal Number Permutation(找规律)

    D. Optimal Number Permutation time limit per test 1 second memory limit per test 256 megabytes input ...

随机推荐

  1. 【8.20校内测试】【DP】【二分+贪心】

    一开始想的贪心,可是发现贪心的问题太多了啊!只能保证当前最优,全局完全无法考虑. 所以正解是dp.预处理出前缀和,枚举每个区间,在每个点记录$now[i]$表示以$i$这个塔结尾的塔组目前的高度.$d ...

  2. ZOJ 3256 Tour in the Castle 插头DP 矩阵乘法

    题解 这题是一道非常好的插头题,与一般的按格转移的题目不同,由于m很大,要矩阵乘法,这题需要你做一个按列转移的插头DP. 按列转移多少与按格转移不同,但大体上还是基于连通性进行转移.每一列只有右插头是 ...

  3. javascritp 字符串截取

    1.substring 方法 定义和用法 substring 方法用于提取字符串中介于两个指定下标之间的字符. 语法 ? stringObject.substring(start,stop) 参数   ...

  4. 搭建MSSM框架(Maven+Spring+Spring MVC+MyBatis)

    https://github.com/easonjim/ssm-framework 先欠着,后续再进行讲解: 一.Spring内核集成 二.Spring MVC集成 三.MyBatis集成 四.代码生 ...

  5. CentOS 6.9永久设置静态路由表以及路由表常用设置

    一.路由表常用设置: 1.使用route命令添加的路由,机器重启或者网卡重启后路由就失效了,方法: //添加到主机的路由 # route add –host 192.168.1.11 dev eth0 ...

  6. Druid 配置 wallfilter

    这个文档提供基于Spring的各种配置方式 使用缺省配置的WallFilter <bean id="dataSource" class="com.alibaba.d ...

  7. (重置adb.exe)android关于The connection to adb is down, and a severe error has occured.这个问题的解决办法

    转自:http://www.sjsjw.com/kf_mobile/article/3_24710_14072.asp 这里补充一个更简单的方法(和下面的方法一样的效果): 有时在打开模拟器的时候会出 ...

  8. Combogrid的onChange和onSelect

    这里只作记录一下 在easyui开发过程中遇到下边两个事儿 combogrid/combotree做级联: $("#" + deptId).combotree( { url : u ...

  9. 仿LOL项目开发第六天

    仿LOL项目开发第六天 by草帽 OK,因为更新模块已经处理好了,接着开始登陆的编写.那么我们就需要状态机的管理. 所谓状态机就是在哪个状态执行那个状态的代码逻辑: 那么我们开始编写GameState ...

  10. Python操作dict时避免出现KeyError的几种方法

    见原文:https://www.polarxiong.com/archives/Python-%E6%93%8D%E4%BD%9Cdict%E6%97%B6%E9%81%BF%E5%85%8D%E5% ...