CF1511G.Chips on a Board

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Alice and Bob have a rectangular board consisting of nn rows and mm columns. Each row contains exactly one chip.

Alice and Bob play the following game. They choose two integers ll and rr such that 1lrm1 \le l \le r \le m and cut the board in such a way that only the part of it between column ll and column rr (inclusive) remains. So, all columns to the left of column ll and all columns to the right of column rr no longer belong to the board.

After cutting the board, they move chips on the remaining part of the board (the part from column ll to column rr ). They make alternating moves, and the player which cannot make a move loses the game. The first move is made by Alice, the second — by Bob, the third — by Alice, and so on. During their move, the player must choose one of the chips from the board and move it any positive number of cells to the left (so, if the chip was in column ii , it can move to any column j<ij < i , and the chips in the leftmost column cannot be chosen).

Alice and Bob have qq pairs of numbers LiL_i and RiR_i . For each such pair, they want to determine who will be the winner of the game if l=Lil = L_i and r=Rir = R_i . Note that these games should be considered independently (they don't affect the state of the board for the next games), and both Alice and Bob play optimally.

输入格式

The first line contains two integers nn and mm ( 1n,m21051 \le n, m \le 2 \cdot 10^5 ) — the number of rows and columns on the board, respectively.

The second line contains nn integers c1,c2,,cnc_1, c_2, \dots, c_n ( 1cim1 \le c_i \le m ), where cic_i is the index of the column where the chip in the ii -th row is located (so, the chip in the ii -th row is in the cic_i -th column).

The third line contains one integer qq ( 1q21051 \le q \le 2 \cdot 10^5 ).

Then qq lines follow, the ii -th of them contains two integers LiL_i and RiR_i ( 1LiRim1 \le L_i \le R_i \le m ).

输出格式

Print a string of qq characters. The ii -th character should be A if Alice wins the game with l=Lil = L_i and r=Rir = R_i , or B if Bob wins it.

输入输出样例

  • 输入#1

    8 10
    1 3 3 7 4 2 6 9
    7
    2 3
    1 3
    1 4
    1 10
    5 10
    8 10
    9 10

    输出#1

    BAAAAAB
首页