The 2020 ICPC Asia Macau Regional Contest G题解

原题目:
Grammy is playing a game with her roommate Alice on a sequence A with n non-negative integers A1,A2,…,An. The rules of the game are described as follows.

They play the game by moving the single token on the sequence, initially the token is at position k.
Grammy takes the first move, and they take moves alternatively.
In any move with the token at position i, the current player must move the token to the next position j such that j>i and Aj differs from Ai on at most one bit in binary representation.
The player who can’t make any legal move loses the game.
They play this game many times and the sequence can be modified many times. Grammy wants to ask you for some initial states who will win the game if both play optimally.

Input
The first line of input contains 2 integers n and m (1≤n,m≤200000), denoting the length of the sequence and the number of operations.

The second line contains n integers A1,A2,…,An (0≤Ai≤255), denoting the sequence A.

The next m lines each contains 2 integers op (1≤op≤2) and k, denoting each operation:

op=1 means a modification on the sequence. Grammy will append an integer k (0≤k≤255) at the end of the sequence so the sequence becomes A1,A2,…,AN+1 where N is the current length of the sequence before modification.
op=2 means a new game starts with the token at position k (1≤k≤N), where N is the current length of the sequence. You need to predict the winner of this game.
Output
For each operation with op=2, output one line containing “Grammy” if Grammy will win, or “Alice” if Alice will win when they play optimally.

题意:
狗蛋和大妮在玩一个游戏,这个游戏一开始在一根轴上有n个位置,每个位置上都有一个数,每个数的大小在0~255之间。游戏一开始有个小人在st这个位置上,每个人需要轮流将小人向右移动到另一个位置u上,要求u位置上的数和当前位置k上的数在二进制上最多只能有一位不同,当轮到一个人不能移动时,这个人便输掉了这轮游戏。在游戏开始之前,游戏可以重复的增加一个数放在数轴的最右边,对于每次询问需要回答谁会赢得这场游戏(假设两人都足够聪明,会采用最优策略)
思路:易发现 对于相同的数,我们只需要考虑最优边的那个数是否为必胜态即可,其他的相同的数均为必胜态,那么我们就可以离散化所有数,再拓扑排一下序,dp转移一下必胜态就出来了。

代码:

#include <bits/stdc++.h>

using namespace std;

const int maxn = 4e5+100;
typedef
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值