CF1037G.A Game on Strings

NOI/NOI+/CTSC

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Alice and Bob are playing a game on strings.

Initially, they have some string tt. In one move the first player selects the character cc present in tt and erases all it's occurrences in tt, thus splitting tt into many smaller strings. The game then goes independently with each of the strings — to make the move player selects one of the strings and one of the characters there, deletes all occurrences and adds the remaining string back to the game.

Alice always starts the game, and then Alice and Bob take turns making moves. The player who is unable to make a move (because there is no string left) loses.

Alice and Bob used to always start with a string ss, but recently they found out that this became too boring. Now before each game they choose two integers ll and rr such that 1≤l≤r≤∣s∣1 \le l \le r \le |s| and play the game with the string slsl+1sl+2…srs_{l} s_{l+1} s_{l+2} \ldots s_{r} instead.

Given the string ss and integers ll, rr for each game. Find who is going to win each game assuming they are smart and are playing optimally.

爱丽丝和鲍勃正在字符串上进行一场游戏。

初始时,他们拥有某个字符串 tt。在一次操作中,先手玩家选择 tt 中存在的某个字符 cc,并删除 tt 中所有该字符的出现,从而将 tt 分割成若干更短的字符串。随后,游戏在每个分割得到的字符串上独立进行——每次操作时,玩家选择其中一个字符串及其中的一个字符,删除该字符在该字符串中的所有出现,并将删除后剩余的(可能为空或多个)子字符串重新加入游戏。

爱丽丝总是先手,之后爱丽丝与鲍勃轮流进行操作。无法进行操作的玩家(即场上已无任何字符串)判负。

过去,爱丽丝和鲍勃总以字符串 ss 作为每局游戏的初始字符串,但最近他们发现这变得过于单调。因此,现在每局游戏开始前,他们会先选定两个整数 ll 和 rr,满足 1≤l≤r≤∣s∣1 \le l \le r \le |s|,并以子串 slsl+1sl+2…srs_{l} s_{l+1} s_{l+2} \ldots s_{r} 作为初始字符串进行游戏。

给定字符串 ss,以及每局游戏对应的整数 ll、rr。假设双方均采取最优策略,请判断每局游戏中谁将获胜。

输入格式

The first line contains the string ss (1≤∣s∣≤1051 \le |s| \le 10^5) consisting of lowercase English letters. This is the string Alice and Bob used to start with.

The second line contains a single integer mm (1≤m≤1051 \le m \le 10^5) — the number of games to analyze.

Each of the next mm lines contains two integers ll and rr (1≤l≤r≤∣s∣1 \le l \le r \le |s|) — the bounds of the starting substring in the string ss.

第一行包含字符串 ss(1≤∣s∣≤1051 \le |s| \le 10^5),由小写英文字母组成。这是爱丽丝和鲍勃最初使用的字符串。

第二行包含一个整数 mm(1≤m≤1051 \le m \le 10^5)——需要分析的游戏场数。

接下来的 mm 行中,每行包含两个整数 ll 和 rr(1≤l≤r≤∣s∣1 \le l \le r \le |s|)——表示字符串 ss 中起始子串的边界。

输出格式

For each game output a single line containing the name of the winner — "Alice" or "Bob" respectively.

对于每局游戏,输出一行,包含获胜者的名字——分别为 “Alice” 或 “Bob”。

输入输出样例

  • 输入#1

    aaab
    2
    1 2
    1 4

    输出#1

    Alice
    Bob
  • 输入#2

    aaccbdb
    2
    5 7
    1 7

    输出#2

    Alice
    Alice

说明/提示

In the first example,

  1. In the first game the string "aa" is selected. Alice deletes character 'a' and Bob is unable to move.
  2. In the second game the string "aaab" is selected. No matter what character Alice will delete, Bob deletes the other one and Alice is unable to move.

In the second example Alice wins both game "bdb" and "aaccbdb".

To win game "bdb" Alice can erase symbol 'd', the game then goes independently on strings "b" and "b". Bob deletes one of this strings and the Alice deletes the other one and Bob is unable to move.

To win game "aaccbdb" Alice can erase symbol 'd', the game then goes independently on strings "aaccb" and "b". It is possible to show, that no matter what are the moves, the remaining game can only finish in exactly 44 moves, so the Bob will be unable to move after that.

在第一个例子中:

  1. 在第一局游戏中,选择字符串 “aa”。爱丽丝删除字符 ‘a’,鲍勃无法继续操作。
  2. 在第二局游戏中,选择字符串 “aaab”。无论爱丽丝删除哪个字符,鲍勃都会删除另一个(同类型的)字符,随后爱丽丝无法继续操作。

在第二个例子中,爱丽丝在两局游戏 “bdb” 和 “aaccbdb” 中均获胜。

要赢得游戏 “bdb”,爱丽丝可以擦除符号 ‘d’,此时游戏将独立地在字符串 “b” 和 “b” 上进行。鲍勃删除其中一个字符串,爱丽丝再删除另一个,之后鲍勃无法继续操作。

要赢得游戏 “aaccbdb”,爱丽丝可以擦除符号 ‘d’,此时游戏将独立地在字符串 “aaccb” 和 “b” 上进行。可以证明:无论双方如何操作,剩余的游戏恰好只能进行 44 步,因此鲍勃在此之后将无法继续操作。

输入解题思路,AI测评打分。不知道怎么写?

首页