Codeforces Round 979 (Div. 2)
D
QED's Favorite Permutation
Codeforces
1700
原题
← CE →
翻译中…

QED is given a permutation$^{\text{∗}}$ $p$ of length $n$. He also has a string $s$ of length $n$ containing only characters $\texttt{L}$ and $\texttt{R}$. QED only likes permutations that are sorted in non-decreasing order. To sort $p$, he can select any of the following operations and perform them any number of times:

翻译中…
  • Choose an index $i$ such that $s_i = \texttt{L}$. Then, swap $p_i$ and $p_{i-1}$. It is guaranteed that $s_1 \neq \texttt{L}$.
  • Choose an index $i$ such that $s_i = \texttt{R}$. Then, swap $p_i$ and $p_{i+1}$. It is guaranteed that $s_n \neq \texttt{R}$.
翻译中…

He is also given $q$ queries. In each query, he selects an index $i$ and changes $s_i$ from $\texttt{L}$ to $\texttt{R}$ (or from $\texttt{R}$ to $\texttt{L}$). Note that the changes are persistent.

翻译中…

After each query, he asks you if it is possible to sort $p$ in non-decreasing order by performing the aforementioned operations any number of times. Note that before answering each query, the permutation $p$ is reset to its original form.

翻译中…

$^{\text{∗}}$A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array).

翻译中…

Input

翻译中…

The first line contains $t$ ($1 \leq t \leq 10^4$) — the number of test cases.

翻译中…

The first line of each test case contains two integers $n$ and $q$ ($3 \leq n \leq 2 \cdot 10^5$, $1 \leq q \leq 2 \cdot 10^5$) – the length of the permutation and the number of queries.

翻译中…

The following line contains $n$ integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq n$, $p$ is a permutation).

翻译中…

The following line contains $n$ characters $s_1s_2 \ldots s_n$. It is guaranteed that $s_i$ is either $\texttt{L}$ or $\texttt{R}$, $s_1 = \texttt{R}$, and $s_n = \texttt{L}$.

翻译中…

The following $q$ lines contain an integer $i$ ($2 \leq i \leq n-1$), denoting that $s_i$ is changed from $\texttt{L}$ to $\texttt{R}$ (or from $\texttt{R}$ to $\texttt{L}$).

翻译中…

It is guaranteed that the sum of $n$ and $q$ over all test cases does not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

For each query, output "YES" (without quotes) if it is possible, and "NO" (without quotes) otherwise.

翻译中…

You can output "YES" and "NO" in any case (for example, strings "yES", "yes" and "Yes" will be recognized as a positive response).

翻译中…

Note

翻译中…

In the first testcase, $s = \texttt{RRRLL}$ after the first query. QED may sort $p$ using the following operations:

翻译中…
  • Initially, $p = [1,4,2,5,3]$.
  • Select $i = 2$ and swap $p_2$ with $p_{3}$. Now, $p = [1,2,4,5,3]$.
  • Select $i = 5$ and swap $p_5$ with $p_{4}$. Now, $p = [1,2,4,3,5]$.
  • Select $i = 4$ and swap $p_4$ with $p_{3}$. Now, $p = [1,2,3,4,5]$, which is in non-decreasing order.
翻译中…

It can be shown that it is impossible to sort the array after all three updates of the first testcase.

翻译中…

样例

Input #1
3
5 3
1 4 2 5 3
RLRLL
2
4
3
8 5
1 5 2 4 8 3 6 7
RRLLRRRL
4
3
5
3
4
6 2
1 2 3 4 5 6
RLRLRL
4
5
Output #1
YES
YES
NO
NO
YES
NO
NO
NO
YES
YES
InputCopy OutputCopy
题目信息
题号
2030D
时间限制
2 s
内存限制
256 MB
标签
数据结构
模拟
排序

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