codeforces 558D Guess Your Way Out! II 规律
题意:
给出n和q

q个提示 格式: deep [l, r] ok
目标:
思路:
首先把全部提示的区间都映射到叶子节点上
先把一定不在的问题转成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 规律的更多相关文章
- 区间合并 --- Codeforces 558D : Gess Your Way Out ! II
D. Guess Your Way Out! II Problem's Link: http://codeforces.com/problemset/problem/558/D Mean: 一棵满二叉 ...
- CodeForces 558D
Guess Your Way Out! II Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...
- Codeforces Gym 100015A Another Rock-Paper-Scissors Problem 找规律
Another Rock-Paper-Scissors Problem 题目连接: http://codeforces.com/gym/100015/attachments Description S ...
- Codeforces Gym 100114 A. Hanoi tower 找规律
A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descript ...
- LightOJ1245 Harmonic Number (II) —— 规律
题目链接:https://vjudge.net/problem/LightOJ-1245 1245 - Harmonic Number (II) PDF (English) Statistics ...
- codeforces Gym 100418D BOPC 打表找规律,求逆元
BOPCTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?c ...
- [CodeForces - 848B] Rooter's Song 思维 找规律
大致题意: 有一个W*H的长方形,有n个人,分别站在X轴或Y轴,并沿直线向对面走,第i个人在ti的时刻出发,如果第i个人与第j个人相撞了 那么则交换两个人的运动方向,直到走到长方形边界停止,问最后每个 ...
- Codeforces Round #242 (Div. 2)C(找规律,异或运算)
一看就是找规律的题.只要熟悉异或的性质,可以秒杀. 为了防止忘记异或的规则,可以把异或理解为半加运算:其运算法则相当于不带进位的二进制加法. 一些性质如下: 交换律: 结合律: 恒等律: 归零律: 典 ...
- codeforces 622D D. Optimal Number Permutation(找规律)
D. Optimal Number Permutation time limit per test 1 second memory limit per test 256 megabytes input ...
随机推荐
- 【多重背包小小的优化(。・∀・)ノ゙】BZOJ1531-[POI2005]Bank notes
[题目大意] Byteotian Bit Bank (BBB) 拥有一套先进的货币系统,这个系统一共有n种面值的硬币,面值分别为b1, b2,..., bn. 但是每种硬币有数量限制,现在我们想要凑出 ...
- [QSCOJ39]喵哈哈村的代码传说 第五章 找规律
题目大意: 给你n堆排,两人轮流对其中一堆牌进行以下操作之一: 1.从这堆牌中取出任意数量的牌: 2.将这这堆牌分为任意大小的3堆牌. 不能操作者负. 问先手是否有必胜策略. 思路: 尝试构造sg函数 ...
- iOS Core Animation 动画 入门学习(一)基础
reference:https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreAnimation_guide ...
- python开发_类型转换convert
在python的开发过程中,难免会遇到类型转换,这里给出常见的类型转换demo: int(x [,base ]) 将x转换为一个整数 long(x [,base ]) 将x转换为一个长整数 float ...
- python输出字符串,UnicodeEncodeError: 'ascii' codec can't encode characters in position问题
2017-06-28更新:换到python3.x中,编码问题减少了很多.这篇博文不适用于python3.x http://blog.sina.com.cn/s/blog_64a3795a01018vy ...
- MySQL5.7添加授权账号及修改默认端口
1.修改默认端口 打开配置文件 vim /etc/my.cnf 分别添加端口在client.mysql节点 [client] port=15099 [mysqld] port=15099 需要注意se ...
- Process ID, Process handle, Window handle
http://forums.codeguru.com/showthread.php?392273-RESOLVED-How-to-get-window-s-HWND-from-it-s-process ...
- GCC安装UBUNTU
在Ubuntu下安装GCC和其他一些Linux系统有点不一样. 方法一: 该方法超简单:sudo apt-get build-depgcc 就上面这条命令就可以搞定 方法二:sudo apt-get ...
- Effective C++:条款29:为“异常安全”而努力是值得的
(一)先看以下这些代码: class PrettyMenu { public: void changeBackground(istream& imgSrc); private: Mutex m ...
- VS2017安装后如何移动 Windows Kits文件夹
MS的回答 LINK Try the following technique: Close all programs, move the “Windows Kits” folder to anothe ...