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 

using namespace std;

const int maxn = 4e5+100;
typedef

你可能感兴趣的:(ACM,补题,动态规划,acm竞赛)