#P15730. [JAG 2024 Summer Camp #2] Broken Parentheses

[JAG 2024 Summer Camp #2] Broken Parentheses

题目描述

Let us define a correct parenthesis sequence as a string that satisfies any of the following conditions:

  • It is an empty string.
  • It is formed by concatenating ((, AA, )) in this order where AA is a correct parenthesis sequence.
  • It is formed by concatenating AA and BB in this order where AA and BB are non-empty correct parenthesis sequences.

Given a string SS of length NN consisting of the characters (( and )).

For each ii where 0iN0 \leq i \leq N, define the string TiT_i as the string obtained by concatenating the suffix of SS of length NiN - i and the reversed string of the prefix of SS of length ii, in this order. That is, if we denote the ii-th character of SS as SiS_i, the string TiT_i is formed by arranging the characters $S_{i+1}, S_{i+2}, \ldots, S_N, S_i, \ldots, S_2, S_1$ in sequence.

For each TiT_i where 0iN0 \leq i \leq N, solve the following problem:

  • Consider an operation where you replace one character in TiT_i with either (( or )). Find the minimum number of such operations required to make TiT_i a correct parenthesis sequence.

输入格式

The input is given in the following format:

NS\begin{aligned} &N \\ &S \end{aligned}
  • 2N200,0002 \leq N \leq 200,000
  • NN is even.
  • SS is a string of length NN consisting only of (( and )).

输出格式

Output N+1N + 1 lines. On the i+1i + 1-th line, output the answer for TiT_i.

4
()()
0
2
2
2
2
6
)))(((
4
2
2
0
0
0
0
8
)())())(
3
1
3
1
1
1
1
1
1