Official algorithmic problem description and constraints.
Monocarp has a deck of cards numbered from 1
to π
. Initially, the cards are arranged from smallest to largest, with 1
on top and π
at the bottom.
Monocarp performed π
actions on the deck. Each action was one of three types:
Your task is to determine the fate of each card: whether it remains in the deck, has been removed, or might be both.
Input
The first line contains a single integer π‘
(1β€π‘β€10
4
) β the number of test cases.
The first line of each test case contains two integers π
and π
(1β€πβ€πβ€2β 10
5
).
The second line contains a string π
of length π
, consisting of characters 0, 1, and/or {2}. This string describes Monocarp's actions. If the π
-th character is 0, Monocarp removes the top card on the π
-th action. If it's 1, he removes the bottom card. If it's 2, either the top or bottom card can be removed.
Additional constraint on the input: the sum of π
over all test cases doesn't exceed 2β 10
5
.
Output
For each test case, print a string consisting of π
characters. The π
-th character should be + (plus sign) if the π
-th card is still in the deck, - (minus sign) if it has been removed, or ? (question mark) if its state is unknown.
Example
Input
4 4 2 01 3 2 22 1 1 2 7 5 01201
Output
-++- ??? - --?+?--
Detailed video explanations, mathematical intuition, and clean C++ implementation code.