#P8536. Constructing a Record-Breaking Permutation

    ID: 21703 Type: Default 1000ms 256MiB

Constructing a Record-Breaking Permutation

Constructing a Record-Breaking Permutation

You are given a binary string \(b\) of length \(n\) consisting of characters '0' and '1'. You need to construct a permutation \(a\) of \(\{1, 2, \dots, n\}\) such that for every index \(i\) with \(2 \le i \le n\), if we define \(m_i = \max\{a_1, a_2, \dots, a_{i-1}\}\), then the following conditions hold:

  • If \(b_i = 1\), then \(a_i > m_i\) (i.e. \(a_i\) becomes a new record).
  • If \(b_i = 0\), then \(a_i < m_i\).

Note that the value of \(b_1\) does not affect the answer because the condition is only defined for \(i \ge 2\). It can be shown that there always exists at least one permutation satisfying the above conditions. If there are multiple solutions, output any one of them.


Background Story: In an intense bullet-hell game scenario, the character "Rin-Sen" has the ability to manipulate the phases of bullets. Originally, each bullet has a phase given by \(b_i\) (either 0 or 1). Under Rin-Sen’s control, the phases are rearranged into a permutation \(a\) of \(\{1, 2, \dots, n\}\). To make life difficult for the protagonists, the following manipulation rule is applied: for every bullet \(i\) (except the first), its new phase \(a_i\) is compared with the maximum phase among all previous bullets. If the original phase \(b_i\) was 1, then \(a_i\) is set to be greater than this maximum; otherwise, it is set to be less than it. Can you help produce a valid manipulated phase sequence?

inputFormat

The first line contains an integer \(n\) (\(1 \le n \le 10^5\)) representing the length of the binary string.

The second line contains a binary string \(b\) of length \(n\) (each character is either '0' or '1').

outputFormat

Output a permutation \(a\) of the integers \(1, 2, \dots, n\) in a single line separated by spaces, satisfying the conditions described in the problem.

sample

1
0
1

</p>