#P9839. 四暗刻单骑
四暗刻单骑
Problem Description
Alice and Bob really enjoy playing mahjong. After becoming familiar with the rules, they became interested in “Four Concealed Triplets, Single Wait”. In this game, both Alice and Bob have already completed Four Concealed Triplets, are in tenpai, and are preparing for a “Four Concealed Triplets, Single Wait”, so we simplify the situation as follows:
- A mahjong tile can be represented by a positive integer in the range . Tiles with the same number are identical, and tiles with different numbers are different.
- Alice and Bob each have tile in hand. They take turns drawing tiles; the player who draws takes the top tile of the deck. Alice goes first. After drawing, the player will have tiles in hand and must choose one tile to discard. The discarded tile is visible to both players.
- If, when drawing, the two tiles in hand are the same, or if the opponent’s currently discarded tile is the same as the tile in your hand, then that player “wins” (pinyin: he pai) and the game ends immediately.
If all tiles are drawn and no player “wins”, it is judged as an “exhaustive draw”, and the two players are considered tied.
Now Alice and Bob are extremely smart, and they already know all the tiles on the top of the deck, as well as the opponent’s hand tile. They both want to “win”; if they cannot “win” themselves, they will try their best to prevent the opponent from “winning”.
You are given an array of mahjong tiles, indexed as . There are queries. Each query gives , meaning: if Alice’s current hand tile is , Bob’s current hand tile is , and all tiles with indices in are taken in order as the game deck, where tile is on the top of the deck, and Alice and Bob play the game as required, then what will be the final result.
The queries are independent of each other. In particular, it is guaranteed that is odd.
Input Format
Read data from standard input.
The first line contains three positive integers .
The next line contains positive integers, representing in order.
The next lines each contain four positive integers , representing one query.
Output Format
Write to standard output.
For each query, output one character on its own line: if Alice wins, output A; if Bob wins, output B; if it is a draw, output D.
12 3 5
2 3 1 2 3 4 1 3 1 5 4 3
1 2 5 6
5 5 7 12
3 4 3 7
D
B
A
7 6 3
2 3 3 3 1 3 3
1 2 5 7
1 1 5 6
1 3 1 6
2 3 7 7
1 3 3 5
1 2 1 4
A
A
B
D
B
D
Hint
[Sample 1 Explanation]
In the st query, the deck from top to bottom is , Alice’s hand tile is , and Bob’s hand tile is . It is not hard to see that this situation will lead to an “exhaustive draw”.
In the nd query, the deck from top to bottom is , Alice’s hand tile is , and Bob’s hand tile is . At this time, Bob only needs to keep this all the time, and he can “win” when he draws the next ; and Alice cannot discard , because once she discards it, Bob will “win” immediately.
In the rd query, the deck from top to bottom is , Alice’s hand tile is , and Bob’s hand tile is . In the first round, Alice draws a and discards this . In the first round, Bob draws a ; no matter whether he discards this or not, Alice can “win” on her next turn.
[Sample 3]
See and in the attachments.
[Sample 4]
See and in the attachments.
[Constraints]
| Test Point ID | Special Properties | |||
|---|---|---|---|---|
| A, B | ||||
| None | ||||
| A, B | ||||
| B | ||||
| C | ||||
| None | ||||
- Special Property A: For every query, is guaranteed.
- Special Property B: For every query, is guaranteed.
- Special Property C: For every query, is guaranteed.
For of the data, it is guaranteed that , , , , and it is guaranteed that is odd.
Translated by ChatGPT 5