B. Deque Process
Problem Statement
We say that an array of size is bad if and only if there exists such that one of the following conditions holds:
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.
Solution
The basic idea is to remove the minimum of the left and right elements in odd rounds, and remove the maximum of the left and right elements in even rounds.
Refer to the official solution for more details.