CF2128B.Deque Process

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Deque Process

We say that an array aa of size nn is bad if and only if there exists 1in41 \leq i \leq n - 4 such that one of the following conditions holds:

  • $a_i \lt a_{i+1} \lt a_{i+2} \lt a_{i+3} \lt a_{i+4}$
  • $a_i \gt a_{i+1} \gt a_{i+2} \gt a_{i+3} \gt a_{i+4}$

An array is good if and only if it's not bad. For example:

  • a=[3,1,2,4,5,6]a = [3, \color{red}{1, 2, 4, 5, 6}] is bad because a2<a3<a4<a5<a6a_2 \lt a_3 \lt a_4 \lt a_5 \lt a_6.
  • a=[7,6,5,4,1,2,3]a = [\color{red}{7, 6, 5, 4, 1}, 2, 3] is bad because a1>a2>a3>a4>a5a_1 \gt a_2 \gt a_3 \gt a_4 \gt a_5.
  • a=[7,6,5,1,2,3,4]a = [7, 6, 5, 1, 2, 3, 4] is good.

You're given a permutation^{\text{∗}} p1,p2,,pnp_1, p_2, \ldots, p_n.

You must perform nn turns. At each turn, you must remove either the leftmost or the rightmost remaining element in pp. Let qiq_i be the element removed at the ii-th turn.

Choose which element to remove at each turn so that the resulting array qq is good. We can show that under the given constraints, it's always possible.

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

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t100001 \le t \le 10\,000). The description of the test cases follows.

The first line of each test case contains a single integer nn (5n1000005 \leq n \leq 100\,000) — the length of the array.

The second line of each test case contains nn integers p1,p2,,pnp_1, p_2, \ldots, p_n (1pin1 \leq p_i \leq n, pip_i are pairwise distinct) — elements of the permutation.

It is guaranteed that the sum of nn over all test cases doesn't exceed 200000200\,000.

Output

For each test case, you must output a string ss of length nn. For every 1in1 \leq i \leq n, at the ii-th turn:

  • si=Ls_i = \texttt{L} means that you removed the leftmost element of pp
  • si=Rs_i = \texttt{R} means that you removed the rightmost element of pp

We can show that an answer always exists. If there are multiple solutions, print any of them.

Note

In the first test case, the sequence $\color{blue}{\texttt{RRR}}\color{red}{\texttt{LLLL}}$ results in $q = [\color{blue}{7}, \color{blue}{6}, \color{blue}{5}, \color{red}{1}, \color{red}{2}, \color{red}{3}, \color{red}{4}]$.

In the second test case, the sequence $\color{red}{\texttt{LL}}\color{blue}{\texttt{RR}}\color{red}{\texttt{LL}}\color{blue}{\texttt{RR}}\color{red}{\texttt{L}}$ results in $q = [\color{red}{1}, \color{red}{3}, \color{blue}{2}, \color{blue}{4}, \color{red}{6}, \color{red}{8}, \color{blue}{5}, \color{blue}{7}, \color{red}{9}]$.

Samples

6
7
1 2 3 4 5 6 7
9
1 3 6 8 9 7 5 4 2
12
1 2 11 3 6 4 7 8 12 5 10 9
6
4 1 2 5 6 3
5
1 2 3 5 4
9
5 1 8 6 2 7 9 4 3
RRRLLLL
LLRRLLRRL
LLLLLLLLLLLL
LLLLLL
LLLLL
LLLLLLLLL

在线编程 IDE

建议全屏模式获得最佳体验