Codeforces Round 1053 (Div. 2)
B
Incremental Path
Codeforces
未评级
原题
← AC →
翻译中…
翻译中…

Hacks are disabled in this problem.

翻译中…

There is a strip containing $10^9$ cells, numbered from $1$ to $10^9$. Each cell is either black or white. Initially, $m$ distinct cells $a_1, a_2, \ldots, a_m$ are black, and the others are white.

翻译中…

If a person is on some cell $x$, he might be given two types of commands:

翻译中…
  • $\texttt{A}$: jump to the next cell, i.e. cell $x + 1$;
  • $\texttt{B}$: jump to the next white cell, i.e. the minimum $y \gt x$ such that cell $y$ is white.
翻译中…

There is a string $s$ of length $n$, consisting of $n$ commands. For each $i$ from $1$ to $n$ in order, a person

翻译中…
  • starts from cell $1$;
  • executes the first $i$ commands in the string;
  • colors the last visited cell black (if it was already black, it remains black).
翻译中…

You wonder which cells are black at the end of the process. Print them in increasing order.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains two integers $n$ and $m$ ($1 \leq n \leq 10^5$, $1 \leq m \leq 10^5$) — the number of commands and the number of black cells at the beginning.

翻译中…

The second line of each test case contains a string $s$ of length $n$, consisting of characters $\texttt{A}$ and $\texttt{B}$, representing the commands.

翻译中…

The third line of each test case contains $m$ integers $a_1, a_2, \ldots, a_m$ ($1 \leq a_1 \lt a_2 \lt \ldots \lt a_m \leq 10^9$) — the initial black cells.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$, and the sum of $m$ over all test cases does not exceed $10^5$.

翻译中…

Output

翻译中…

For each test case, print two lines:

翻译中…
  • in the first line, print a single integer $k$: the number of black cells at the end;
  • in the second line, print the labels of the black cells, in increasing order.
翻译中…

Note

翻译中…

In the first test case, initially the only black cells are $2$ and $5$.

翻译中…

Person $1$:

翻译中…
  • starts from cell $1$;
  • executes command $\texttt{B}$, going to the next white cell ($3$);
  • colors cell $3$ black.
翻译中…

Person $2$:

翻译中…
  • starts from cell $1$;
  • executes command $\texttt{B}$, going to the next white cell ($4$);
  • executes command $\texttt{A}$, going to the next cell ($5$);
  • colors cell $5$ black (it was already black, so it remains black).
翻译中…

Person $3$:

翻译中…
  • starts from cell $1$;
  • executes command $\texttt{B}$, going to the next white cell ($4$);
  • executes command $\texttt{A}$, going to the next cell ($5$);
  • executes command $\texttt{B}$, going to the next white cell ($6$);
  • colors cell $6$ black.
翻译中…

At the end, the black cells are $\{2, 3, 5, 6\}$.

翻译中…

In the second test case, the three people end up in cells $2$, $3$, and $6$, respectively.

翻译中…

样例

Input #1
5
3 2
BAB
2 5
3 4
ABA
1 4 9 10
5 2
ABABB
1 7
3 1
BBA
6
1 4
A
1 3 4 1000000000
Output #1
4
2 3 5 6
7
1 2 3 4 6 9 10
7
1 2 3 5 6 7 9
3
2 4 6
5
1 2 3 4 1000000000
InputCopy OutputCopy
题目信息
题号
2151B
时间限制
1 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。