QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB

#21383. 消失的逆序對

Statistics

Alice 和 Bob 正在一個排列上玩遊戲,由 Alice 先手。

一個長度為 $n$ 的序列被稱為排列,若且唯若 $1, 2, \ldots, n$ 中的每個整數都在該序列中恰好出現一次。

初始時,給定一個長度為 $n$ 的排列 $a_1, a_2, \ldots, a_n$。在遊戲過程中的任意時刻,當前序列始終是某個長度為 $m$ 的排列。兩名玩家輪流操作,每回合當前玩家必須從以下兩種操作中選擇一種執行:

  • 選擇一個滿足 $a_i > a_{i+1}$ 的索引 $i$($1 \le i < m$),並交換 $a_i$ 和 $a_{i+1}$;
  • 選擇一個滿足 $a_{i+1} = a_i + 1$ 的索引 $i$($1 \le i < m$),刪除 $a_i$ 和 $a_{i+1}$,然後按照剩餘元素的相對大小順序對它們重新編號:將剩餘元素中第 $k$ 小的元素重新編號為 $k$,使得剩餘序列再次成為一個排列。

例如,假設當前排列為 $[2, 3, 4, 1]$。可以刪除相鄰元素 $2$ 和 $3$,剩下 $[4, 1]$;重新編號後,排列變為 $[2, 1]$。

無法執行任何操作的玩家輸掉遊戲。假設 Alice 和 Bob 都採取最佳策略,請判斷誰會獲勝。

輸入格式

本題單個測試點包含多組測試資料。

第一行包含一個整數 $T$($1 \le T \le 5000$),表示測試資料的組數。

對於每組測試資料:

  • 第一行包含一個整數 $n$($1 \le n \le 5000$)。
  • 第二行包含 $n$ 個整數 $a_1, a_2, \ldots, a_n$。保證 $a$ 是一個長度為 $n$ 的排列。

保證所有測試資料中 $n$ 的總和不超過 $5000$。

輸出格式

對於每組測試資料,如果 Alice 獲勝,輸出 Alice;否則輸出 Bob。

範例

輸入格式 1

5
1
1
2
1 2
2
2 1
4
2 4 1 3
5
5 1 4 2 3

輸出格式 1

Bob
Alice
Bob
Alice
Bob

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.