#P9839. 四暗刻单骑

    ID: 10726 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>贪心树形数据结构博弈论线段树洛谷原创O2优化洛谷月赛

四暗刻单骑

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 [1,k][1, k]. Tiles with the same number are identical, and tiles with different numbers are different.
  • Alice and Bob each have 11 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 22 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 aa of nn mahjong tiles, indexed as 1n1 \dots n. There are mm queries. Each query gives x,y,l,rx, y, l, r, meaning: if Alice’s current hand tile is xx, Bob’s current hand tile is yy, and all tiles aa with indices in [l,r][l, r] are taken in order as the game deck, where tile ala_l 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 ll is odd.

Input Format

Read data from standard input.

The first line contains three positive integers n,m,kn, m, k.

The next line contains nn positive integers, representing a1,a2ana_1, a_2 \dots a_n in order.

The next mm lines each contain four positive integers x,y,l,rx, y, l, r, 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 11st query, the deck from top to bottom is 3,43, 4, Alice’s hand tile is 11, and Bob’s hand tile is 22. It is not hard to see that this situation will lead to an “exhaustive draw”.

In the 22nd query, the deck from top to bottom is 1,3,1,5,4,31, 3, 1, 5, 4, 3, Alice’s hand tile is 55, and Bob’s hand tile is 55. At this time, Bob only needs to keep this 55 all the time, and he can “win” when he draws the next 55; and Alice cannot discard 55, because once she discards it, Bob will “win” immediately.

In the 33rd query, the deck from top to bottom is 1,2,3,4,11, 2, 3, 4, 1, Alice’s hand tile is 33, and Bob’s hand tile is 44. In the first round, Alice draws a 11 and discards this 11. In the first round, Bob draws a 22; no matter whether he discards this 22 or not, Alice can “win” on her next turn.


[Sample 3]

See mahjong/mahjong3.in\verb!mahjong/mahjong3.in! and mahjong/mahjong3.ans\verb!mahjong/mahjong3.ans! in the attachments.


[Sample 4]

See mahjong/mahjong4.in\verb!mahjong/mahjong4.in! and mahjong/mahjong4.ans\verb!mahjong/mahjong4.ans! in the attachments.


[Constraints]

Test Point ID nn\le mm\le kk\le Special Properties
11 33 A, B
22 55 None
353\sim 5 100100
676\sim 7 20002000
8108\sim 10 5×1045\times 10^4 5050 5×1045\times 10^4
1111 2×1052\times 10^5 22
1212 8080
1313 2×1052\times 10^5 A, B
141514\sim 15 B
1616 C
172017\sim 20 10510^5 None
212521\sim 25 2×1052\times 10^5
  • Special Property A: For every query, l=1l = 1 is guaranteed.
  • Special Property B: For every query, r=nr = n is guaranteed.
  • Special Property C: For every query, x=yx = y is guaranteed.

For 100%100\% of the data, it is guaranteed that 3n2×1053 \leq n \leq 2\times 10^5, 1m2×1051 \leq m \leq 2\times 10^5, 1ai,x,ykn1 \leq a_i, x, y \leq k \leq n, 1lrn1 \leq l \leq r \leq n, and it is guaranteed that ll is odd.

Translated by ChatGPT 5