欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2128B.Deque Process
Deque Process
We say that an array of size is bad if and only if there exists 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:
- is bad because .
- is bad because .
- is good.
You're given a permutation .
You must perform turns. At each turn, you must remove either the leftmost or the rightmost remaining element in . Let be the element removed at the -th turn.
Choose which element to remove at each turn so that the resulting array is good. We can show that under the given constraints, it's always possible.
A permutation of length is an array consisting of distinct integers from to in arbitrary order. For example, is a permutation, but is not a permutation ( appears twice in the array), and is also not a permutation ( but there is in the array).
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains a single integer () — the length of the array.
The second line of each test case contains integers (, are pairwise distinct) — elements of the permutation.
It is guaranteed that the sum of over all test cases doesn't exceed .
Output
For each test case, you must output a string of length . For every , at the -th turn:
- means that you removed the leftmost element of
- means that you removed the rightmost element of
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
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |