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 ...
随机推荐
- java-银行卡基本信息查询
用于验证的请求接口: https://ccdcapi.alipay.com/validateAndCacheCardInfo.json?_input_charset=utf-8&cardNo= ...
- bzoj 2152
/************************************************************** Problem: 2152 User: idy002 Language: ...
- Rails -- 关于Migration
Rails -- 关于Migration 无聊去逛博客,发现一篇介绍Migration,挺详细的,留个链接,以后需要的时候看. 链接: http://www.cnblogs.com/orez88/ar ...
- 比较page、request、session、application的使用范围(转自用)
(1)直接在web contain中进行对象的实例化. 内置对象 类型 作用域 pageContext javax.servlet.jsp.pageContext page request javax ...
- How to use transparent PNG icons with Delphi ImageList
http://www.aha-soft.com/faq/delphi-imagelist-png.htm Query: "Embarcadero Delphi ImageList does ...
- Changing the Output Voltage of a Switching Regulator on the Fly
http://www.powerguru.org/changing-the-output-voltage-of-a-switching-regulator-on-the-fly/ There are ...
- jQuery:validate表单验证基本使用
jquery.validate是jquery的一个验证框架,可以迅速验证一些常见的输入,并且可以自己扩充自己的验证方法! 这里先从介绍简单的使用方法:jquery.validate.js下载地址 1. ...
- java代码逆向工程生成uml
今天在看一个模拟器的源码,一个包里有多个类,一个类里又有多个属性和方法,如果按顺序看下来,不仅不能对整个模拟器的框架形成一个大致的认识,而且只会越看越混乱,所以,想到有没有什么工具可以将这些个类以及它 ...
- 使用HttpClient发送请求接收响应
1.一般需要如下几步:(1) 创建HttpClient对象.(2)创建请求方法的实例,并指定请求URL.如果需要发送GET请求,创建HttpGet对象:如果需要发送POST请求,创建HttpPost对 ...
- Scrum 思考
下个月就要离职,所以这个月特别清闲,上班时间都在上网看书,偶然在Startup News的一篇文章(http://blog.devtang.com/blog/2013/06/17/startup-an ...