CF1511G.Chips on a Board
省选/NOI-
通过率:0%
时间限制:5.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Alice and Bob have a rectangular board consisting of n rows and m columns. Each row contains exactly one chip.
Alice and Bob play the following game. They choose two integers l and r such that 1≤l≤r≤m and cut the board in such a way that only the part of it between column l and column r (inclusive) remains. So, all columns to the left of column l and all columns to the right of column r no longer belong to the board.
After cutting the board, they move chips on the remaining part of the board (the part from column l to column r). 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 i, it can move to any column j<i, and the chips in the leftmost column cannot be chosen).
Alice and Bob have q pairs of numbers Li and Ri. For each such pair, they want to determine who will be the winner of the game if l=Li and r=Ri. 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.
爱丽丝和鲍勃有一块由 n 行 m 列组成的矩形棋盘。每行恰好有一枚棋子。
爱丽丝和鲍勃进行如下游戏:他们选择两个整数 l 和 r,满足 1≤l≤r≤m,并将棋盘沿列方向裁剪,仅保留第 l 列到第 r 列(含端点)之间的部分。因此,第 l 列左侧的所有列和第 r 列右侧的所有列均不再属于棋盘。
裁剪后,他们在剩余部分(即第 l 列至第 r 列)上移动棋子。双方轮流行动,无法行动的一方判负。先手为爱丽丝,第二步由鲍勃执行,第三步由爱丽丝执行,依此类推。在自己的回合中,玩家必须从棋盘上选择一枚棋子,并将其向左移动任意正整数个格子(即若该棋子当前位于第 i 列,则可移至任意第 j 列,其中 j<i;最左侧列中的棋子无法被选中)。
爱丽丝和鲍勃共有 q 对数字 (Li,Ri)。对每一对,他们希望确定:当 l=Li 且 r=Ri 时,游戏的获胜者是谁。注意,这些游戏彼此独立(前一局的结果不会影响后续棋盘的状态),且爱丽丝与鲍勃均采用最优策略。
输入格式
The first line contains two integers n and m (1≤n,m≤2⋅105) — the number of rows and columns on the board, respectively.
The second line contains n integers c1,c2,…,cn (1≤ci≤m), where ci is the index of the column where the chip in the i-th row is located (so, the chip in the i-th row is in the ci-th column).
The third line contains one integer q (1≤q≤2⋅105).
Then q lines follow, the i-th of them contains two integers Li and Ri (1≤Li≤Ri≤m).
第一行包含两个整数 n 和 m(1≤n,m≤2⋅105),分别表示棋盘的行数和列数。
第二行包含 n 个整数 c1,c2,…,cn(1≤ci≤m),其中 ci 表示第 i 行中棋子所在的列号(即第 i 行的棋子位于第 ci 列)。
第三行包含一个整数 q(1≤q≤2⋅105)。
接下来有 q 行,其中第 i 行包含两个整数 Li 和 Ri(1≤Li≤Ri≤m)。
输出格式
Print a string of q characters. The i-th character should be A if Alice wins the game with l=Li and r=Ri, or B if Bob wins it.
输出一个长度为 q 的字符串。其中第 i 个字符应为 A(若 Alice 在 l=Li 且 r=Ri 时赢得游戏),或 B(若 Bob 赢得游戏)。
输入输出样例
输入#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
输入解题思路,AI测评打分。不知道怎么写?