#P17443. 消失的逆序对 / Vanishing Inversions

消失的逆序对 / Vanishing Inversions

Problem Description

Alice and Bob play a game on a permutation, with Alice moving first.

A sequence of length nn is called a permutation if and only if every integer in 1,2,…,n1,2,\dots,n appears in the sequence exactly once.

Initially, a permutation a1,a2,…,ana_1,a_2,\ldots,a_n of length nn is given. At any moment during the game, the current sequence is always a permutation of length mm. The two players take turns, and on each turn they must choose one of the following operations:

  • Choose an index ii (1≤i<m)(1\le i<m) such that ai>ai+1a_i>a_{i+1}, and swap aia_i and ai+1a_{i+1}.
  • Choose an index ii (1≤i<m)(1\le i<m) such that ai+1=ai+1a_{i+1}=a_i+1, and delete aia_i and ai+1a_{i+1}. Then renumber the remaining elements according to their relative order: the kk-th smallest remaining element is renumbered as kk, so that the remaining sequence becomes a permutation again.

For example, if the current permutation is [2,3,4,1][2,3,4,1], you may delete the adjacent 2,32,3, leaving [4,1][4,1]; after renumbering, the permutation becomes [2,1][2,1].

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 TT (1≤T≤5000)(1\le T\le 5000), the number of test cases.

For each test case:

  • The first line contains an integer nn (1≤n≤5000)(1\le n\le 5000).
  • The second line contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n, and it is guaranteed that aa is a permutation of length nn.

It is guaranteed that the sum of nn over all test cases does not exceed 50005000.

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