Codeforces Round 832 (Div2)
Swap Game
Alice 和 Bob 两个人在玩游戏。
有一个长度为 \(n\) 的序列 \(a\),Alice 和 Bob 两人轮流完成一个操作,Alice 先开始。
每个人可以将数列的第一个数减 \(1\),并将它与后面序列的一个数进行交换,如果一个人操作之前发现当前序列中的第一个数为 \(0\),这个人就输了。
问如果两人都足够聪明,最后谁会赢?
题解:
我们发现必败态是\(a_1=0\),我们考虑由于两个人都会选择最优的策略,也就是说每个人一定会挑\([2,n]\)中最小的数和\(a_1\)交换,因为这样能使得对方快速遇到\(a_1=0\),所以说必败态为\(a_1\)是最小值;
- 如果一开始\(a_1\)本身就是最小值,也就是说Alice开局就是必败态,那么他无论如何都走不到一个必败态,也就是说Bob始终能留给Alice必败态的局面,所以Alice必败
- 如果一开始\(a_1\)不是最小值,那么Alice每次都能抛给bob必败态,所以Alice必胜
#include <bits/stdc++.h>
#define Zeoy std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0)
#define debug(x) cerr << #x << '=' << x << endl
#define all(x) (x).begin(), (x).end()
#define rson id << 1 | 1
#define lson id << 1
#define int long long
#define mpk make_pair
#define endl '\n'
using namespace std;
typedef unsigned long long ULL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-9;
const int N = 2e5 + 10, M = 4e5 + 10;
int n;
void solve()
{
cin >> n;
int res = 0;
int a;
cin >> a;
bool flag = false;
for (int i = 2; i <= n; ++i)
{
int x;
cin >> x;
if (x < a)
{
flag = true;
}
}
if (flag)
cout << "Alice" << endl;
else
cout << "Bob" << endl;
}
signed main(void)
{
Zeoy;
int T = 1;
cin >> T;
while (T--)
{
solve();
}
return 0;
}
Yet Another Problem
给定长度为\(n\)序列\(a\),存在\(q\)次询问,每次询问给定区间\([l,r]\),现在支持这样的操作:选定一段奇数长度的区间\(l\leq L\leq R\leq r\),可以使得这段区间的所有元素变成\(a_L\bigoplus a_{L+1}...\bigoplus a_R\),对于每次询问回答至少需要多少次操作才能使得区间\([l,r]\)中的所有元素都变成0,如果无法成功输出\(-1\)
\(1\leq a_i \leq 2^{30}\)
题解:二进制 + 思维 + 二分 + 离散化
我们发现如果区间\([l,r]\)的异或和不为0,一定不可能成功,因为每次选定的是奇数长度的区间
如果区间\([l,r]\)异或和为0,那么存在以下几种情况:
- 如果区间\([l,r]\)中所有元素本来全部为0,最小操作次数为0;
- 如果区间\([l,r]\)的长度为奇数,最小操作次数为1;
- 如果区间\([l,r]\)的长度为偶数:
- 如果\(a[l]=0\) 或者 \(a[r] = 0\),最少操作次数为1;
- 如果该区间存在奇数长度的区间\([l,i]\)异或和为0,那么最小操作次数为2;
- 不满足上面情况的都无法成功
再来讲一下如何快速得知是否存在奇数长度的区间\([l,i]\)异或和为0,我们可以邻接表维护每一个前缀异或和的奇数位置和偶数位置,如果\(l\)为奇数我们就在相同前缀异或和中找到大于\(l\)的第一个奇数位置,如果\(l\)是偶数位置同理;但是我们发现\(a_i\)太大了,所以我们需要利用哈希表离散化(映射)
#include <bits/stdc++.h>
#define Zeoy std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0)
#define debug(x) cerr << #x << '=' << x << endl
#define all(x) (x).begin(), (x).end()
#define rson id << 1 | 1
#define lson id << 1
#define int long long
#define mpk make_pair
#define endl '\n'
using namespace std;
typedef unsigned long long ULL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-9;
const int N = 1e6 + 10, M = 4e5 + 10;
int n, q;
int a[N];
int pre[N];
int sum[N];
unordered_map<int, vector<int>> mp1, mp2;
void solve()
{
cin >> n >> q;
for (int i = 1; i <= n; ++i)
cin >> a[i];
for (int i = 1; i <= n; ++i)
{
sum[i] = sum[i - 1] + (a[i] == 0);
pre[i] = pre[i - 1] ^ a[i];
}
for (int i = 1; i <= n; ++i)
{
if (i % 2 == 1)
mp1[pre[i]].push_back(i);
else
mp2[pre[i]].push_back(i);
}
while (q--)
{
int l, r;
cin >> l >> r;
if (pre[r] != pre[l - 1])
{
cout << -1 << endl;
continue;
}
if (sum[r] - sum[l - 1] == r - l + 1)
{
cout << 0 << endl;
continue;
}
if ((r - l + 1) % 2 == 1)
{
cout << 1 << endl;
continue;
}
if (a[l] == 0 || a[r] == 0)
{
cout << 1 << endl;
continue;
}
int x = pre[l - 1];
if (l % 2 == 1)
{
int p = lower_bound(all(mp1[x]), l) - mp1[x].begin();
if (p == mp1[x].end() - mp1[x].begin() || mp1[x][p] > r)
{
cout << -1 << endl;
continue;
}
cout << 2 << endl;
}
else
{
int p = lower_bound(all(mp2[x]), l) - mp2[x].begin();
if (p == mp2[x].end() - mp2[x].begin() || mp2[x][p] > r)
{
cout << -1 << endl;
continue;
}
cout << 2 << endl;
}
}
}
signed main(void)
{
Zeoy;
int T = 1;
// cin >> T;
while (T--)
{
solve();
}
return 0;
}
Codeforces Round 832 (Div2)的更多相关文章
- A. Launch of Collider Codeforces Round #363 (Div2)
A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #539 div2
Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...
- 【前行】◇第3站◇ Codeforces Round #512 Div2
[第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...
- Codeforces Round#320 Div2 解题报告
Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...
- Codeforces Round #564(div2)
Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...
- Codeforces Round #361 div2
ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...
- codeforces 572(Div2)A、B、C、D1、D2、E
Cdoeforces 572(Div2)A.B.C.D1.D2.E 传送门:https://codeforces.com/contest/1189 A.题意: 给你一串长为n的字符串,要求你将其切割为 ...
- Codeforces Round #626 Div2 D,E
比赛链接: Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) D.Present 题意: 给定大 ...
- codeforces round 472(DIV2)D Riverside Curio题解(思维题)
题目传送门:http://codeforces.com/contest/957/problem/D 题意大致是这样的:有一个水池,每天都有一个水位(一个整数).每天都会在这一天的水位上划线(如果这个水 ...
- Codeforces Round #626 Div2 D. Present(位掩码,二分)
题目链接:https://codeforces.com/contest/1323/problem/D 题意:给了大小为4e5的数组a,其中1<=ai<=1e7.求所有点对和的异或和,即: ...
随机推荐
- C++ weak_ptr除了解决循环引用还能做什么?
C++: weak_ptr到底有什么用? 很多人对std::weak_ptr的认识只是不增加std::shared_ptr的引用计数,可以用来解决std::shared_ptr可能造成的循环引用问题. ...
- JWT单点登录
单点登录 概念:登录某集团的某一产品之后,访问其他产品的网站时就会是登录状态,比如登录QQ之后,进入QQ游戏的时候就是登录过的状态,具体实现方法有以下: Redis+token实现单点登录: 生成一个 ...
- CSS – Transition & Animation
前言 之前的笔记 CSS – W3Schools 学习笔记 (3) 就有讲过 CSS Transitions 和 CSS Animations. 这里做一个整理, 补上一些细节. Transition ...
- 【学习笔记】数位DP
数位DP 适用条件 此类题目一般要求在\([l,r]\)区间内满足条件的数的个数,答案一般与数的大小无关,而与数各位的组成有关.题目中给出的数的范围一般较大,往往在\(10^9\)以上因此无法暴力枚举 ...
- 【译】通过新的 WinUI 工作负荷和模板改进,深入原生 Windows 开发
在 Build 2024 上,WinUI 团队宣布将重新关注 WinUI,将其作为我们推荐的原生 Windows 应用开发的首要应用开发框架之一.为了使其尽可能无缝和轻松地进入编码,我们创建了一个新的 ...
- “全栈合一 智慧运维”智和网管平台SugarNMS V9版本发布
以"管控万物 无所不能 无处不"在为产品创新理念,智和信通打造"全栈式"网络安全运维平台-智和网管平台SugarNMS.立足数字化.智能化.可视化.自动化,整合 ...
- /proc/slabinfo 介绍
slabinfo - version: 2.1 # name <active_objs> <num_objs> <objsize> <objperslab&g ...
- Android Qcom USB Driver学习(八)
因为要看usb charging的问题,所以需要补充一下battery的相关知识,算是入门吧 BAT SCH (1)VBATT_VSNS_P (2)BAT_THERM (3)I2C_SDA (4)I2 ...
- 强大的USB协议分析工具
2020年最后一天了,感谢大家一年来对我文章的支持,有你们的支持就是我强大的动力. 今天来给大家介绍一个USB 协议分析软件LeCroy USB Advisor,软件安装包下载连接如下: 链接:htt ...
- Nessus 安装 笔记
Nessus 安装 笔记 根据 https://www.zwnblog.com/archives/nessus-jie-shao-yu-an-zhuang#2.kali%E5%AE%89%E8%A3% ...