#P8536. 「Wdoi-2」幻胧月睨
「Wdoi-2」幻胧月睨
Background
Problem Number: .
The background is unrelated to the problem. Contestants can directly read the "Brief Statement" below.
This is the story after The Tale of the Bamboo Cutter. It has already been a hundred years since Gensokyo was separated from reality.
After the people of Earth launched an invasion war against the Moon, a moon rabbit named Reisen abandoned her companions, barely survived, and fled to Eientei in Gensokyo, arriving at Kaguya and Eirin's side, living a peaceful and comfortable life.
Several decades later, Reisen received an order from the Moon, demanding that she be forced to return. After discussing it, Kaguya and Eirin decided not to hand Reisen back to the Moon. But to avoid causing trouble, they decided to make the full moon disappear from the Earth, leaving only a fake moon.
To make it easier to investigate the incident, Yukari Yakumo used her power to turn the entire Gensokyo into an eternal night.
Four groups of protagonists, eight people in total, were sent back to the time when the incident happened. Except for Yukari Yakumo, who still kept her memories and could travel back and forth across the boundary between illusion and reality, the others lost their memories and started their journey again to reclaim Gensokyo's full moon.
Guided by Keine, they arrived at the Lost Bamboo Forest. Before them stood a moon rabbit named Reisen.
Problem Description
Brief Statement
Given a binary string of length , construct a permutation of length such that for , let . Then:
- If , then .
- Otherwise, .
It can be proven that there always exists a sequence satisfying the above conditions.
If there are multiple solutions, output any one.
Also note that the value of is arbitrary and has no effect on the sequence .
Original Statement
Reisen has the ability to manipulate the degree of madness, in other words, to manipulate the wavelength, amplitude, and phase of objects. This ability creates various obstacles for the protagonists—for example, manipulating light waves can make the bullets appear and disappear, and can even create a fake self, greatly interfering with dodging.
Take the spell card "Genrou Gatsunei" as an example. In "Genrou Gatsunei", there are bullets, and each bullet has a phase, which is either or . The phases of these bullets form a sequence of length .
Reisen will manipulate the phases of these bullets, making them very strange. Specifically, after being manipulated, the phases become a permutation of length , meaning that every number from to appears in this sequence exactly once.
To make it harder for the protagonists to dodge, Reisen sets a threshold. For each element , the threshold is the maximum value of its prefix, that is, the maximum among . If the phase of the original -th bullet is , then the manipulated phase must be greater than this threshold; otherwise, the manipulated phase must be less than this threshold.
Obviously, according to Reisen's manipulation rules, no matter what the original bullet phases are, there always exists a feasible manipulation plan. Since the protagonists have lost their memories, there is not much time left to retrieve the moon, and bullet battles require very strict time control, they found you and hope that, given Reisen's original bullet phases, you can provide any possible manipulated bullet phases to help them prepare for dodging.
Input Format
This problem has multiple test cases.
The first line contains an integer , denoting the number of test cases.
For each test case:
- The first line contains an integer , with the meaning described above.
- The second line contains a binary string of length .
Output Format
For each test case, output one line with integers, which is the sequence you constructed.
If there are multiple solutions, output any one.
3
3
111
3
101
4
0101
1 2 3
2 1 3
1 3 2 4
Hint
Sample Explanation
- For testdata , obviously .
- For testdata , obviously .
- For testdata , obviously .
Note that also satisfies the requirement.
Constraints
$$\def\arraystretch{1.5} \begin{array}{|c|c|c|c|c|}\hline \textbf{Subtask} & \bm{n\le} & \textbf{特殊性质} & \textbf{Subtask 依赖} & \textbf{分值}\\\hline 1 & 10 & - & - & 5\\\hline 2 & 10^5 & \textbf{A} & - & 5 \\\hline 3 & 10^5 & \textbf{B} & - & 20 \\\hline 4 & 10^5 & - & 1,2,3 &70 \\\hline \end{array}$$- Special property : It is guaranteed that all are equal.
- Special property : There exists an integer such that for , ; and for , .
For all testdata, , , .
It is guaranteed that within a single test point, .
Translated by ChatGPT 5