CF1932C LR-remainders
题目描述
给定一个长度为 $n$ 的数组 $a$,一个正整数 $m$,以及一个长度为 $n$ 的命令字符串。每个命令要么是字符 `L`,要么是字符 `R`。
按照字符串 $s$ 中写入的顺序处理所有 $n$ 个命令。处理命令的步骤如下:
首先,输出数组 $a$ 中所有元素的乘积除以 $m$ 的余数。
然后,如果命令是 `L`,则从数组 $a$ 中移除最左边的元素;如果命令是 `R`,则从数组 $a$ 中移除最右边的元素。
请注意,每次移动后,数组 $a$ 的长度减少 $1$,并且在处理所有命令后,数组将为空。
编写一个程序,按照字符串 $s$ 中写入的顺序从左到右处理所有命令。
输入格式
第一行包含一个整数 $t$($1\le t\le10^4$),表示输入中的测试数据数量。然后是 $t$ 个测试数据的描述。
输入的每个测试数据分 $3$ 出。
第一行包含两个整数 $n$ 和 $m$($1\le n\le2\cdot10^5,1\le m\le10^4$)——数组 $a$ 的初始长度和取余数的值。
第二行包含 $n$ 个整数 $a_1,a_2,\dots,a_n$($1\le a_i\le10^4$),数组 $a$ 的元素。
第三行包含一个由 $ n $ 个字符 `L` 和 `R` 组成的字符串 $s$。
保证一个测试用例中所有 $n$ 值的总和不超过 $2\cdot10^5$。
输出格式
对于每个测试用例,输出 $n$ 个整数 $b_1,b_2,\dots,b_n$,其中 $b_i$ 是在执行第 $i$ 个命令时,当前数组 $a$ 的所有元素的乘积除以 $m$ 的余数。
### 样例解释
在示例的第一个测试用例中:
- $ 3 \cdot 1 \cdot 4 \cdot 2 \bmod 6 = 24 \bmod 6 = 0 $;
- $ s_1 = \text{L} $,因此我们移除第一个元素,得到数组 $ [1, 4, 2] $;
- $ 1 \cdot 4 \cdot 2 \bmod 6 = 8 \bmod 6 = 2 $;
- $ s_2 = \text{R} $,因此我们移除最后一个元素,得到数组 $ [1, 4] $;
- $ 1 \cdot 4 \bmod 6 = 4 \bmod 6 = 4 $;
- $ s_3 = \text{R} $,因此我们移除最后一个元素,得到数组 $ [1] $;
- $ 1 \bmod 6 = 1 $;
- $ s_4 = \text{L} $,因此我们移除第一个元素,得到一个空数组。
说明/提示
In the first test case of the example:
- $ 3 \cdot 1 \cdot 4 \cdot 2 \bmod 6 = 24 \bmod 6 = 0 $ ;
- $ s_1 = \text{L} $ , so we remove the first element and get the array $ [1, 4, 2] $ ;
- $ 1 \cdot 4 \cdot 2 \bmod 6 = 8 \bmod 6 = 2 $ ;
- $ s_2 = \text{R} $ , so we remove the last element and get the array $ [1, 4] $ ;
- $ 1 \cdot 4 \bmod 6 = 4 \bmod 6 = 4 $ ;
- $ s_3 = \text{R} $ , so we remove the last element and get the array $ [1] $ ;
- $ 1 \bmod 6 = 1 $ ;
- $ s_4 = \text{L} $ , so we remove the first element and get an empty array.