#P17443. 消失的逆序对 / Vanishing Inversions
消失的逆序对 / Vanishing Inversions
Problem Description
Alice and Bob play a game on a permutation, with Alice moving first.
A sequence of length is called a permutation if and only if every integer in appears in the sequence exactly once.
Initially, a permutation of length is given. At any moment during the game, the current sequence is always a permutation of length . The two players take turns, and on each turn they must choose one of the following operations:
- Choose an index such that , and swap and .
- Choose an index such that , and delete and . Then renumber the remaining elements according to their relative order: the -th smallest remaining element is renumbered as , so that the remaining sequence becomes a permutation again.
For example, if the current permutation is , you may delete the adjacent , leaving ; after renumbering, the permutation becomes .
When a player cannot make any move, that player loses. Assuming both Alice and Bob play optimally, determine the winner.
Input Format
This problem has multiple test cases.
The first line contains an integer , the number of test cases.
For each test case:
- The first line contains an integer .
- The second line contains integers , and it is guaranteed that is a permutation of length .
It is guaranteed that the sum of over all test cases does not exceed .
Output Format
For each test case, if Alice wins, output Alice; otherwise output Bob.
5
1
1
2
1 2
2
2 1
4
2 4 1 3
5
5 1 4 2 3
Bob
Alice
Bob
Alice
Bob
Hint
Translated by ChatGPT 5