qarentheziz zepuence

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

Ryan is interested in strings consisting only of ‘(' and ‘)'. Especially, he loves balanced strings. Any balanced strings can be constructed using the following rules:

  • A string “()" is balanced.
  • The concatenation of two balanced strings is balanced.
  • If TT is a balanced string, the concatenation of ‘(', TT, and ‘)' in this order is balanced.

For example, “()()" and “(()())" are balanced strings. “)(", “)()(()" and “(" are not balanced strings.

We define Ryan's sadness for a string TT as the minimum number of operations required to make TT into a balanced string by doing the following operations in any order and any number of times.

  • Add ‘)' to the beginning of TT.
  • Add ‘(' to the end of TT.
  • Swap two adjacent characters of TT.

Ryan has a string SS of length NN consisting only of ‘(' and ‘)'. Given QQ queries, process them in order. There are two kinds of queries with the following formats.

  • 11 ll rr": For each character from the ll-th to the rr-th (including rr-th) of SS, if it is ‘(', replace it with ‘)'. If it is ‘)', replace it with ‘('.
  • 22 ll rr": Output the value of Ryan's sadness for the substring from the ll-th through rr-th characters of SS.

입력

The input consists of a single test case of the following format.

NN QQ

SS

t_1t\_1 l_1l\_1 r_1r\_1

\vdots

t_Qt\_Q l_Ql\_Q r_Qr\_Q

The first line contains two integers NN and QQ (2N150,0002 ≤ N ≤ 150\\,000, 1Q150,0001 ≤ Q ≤ 150\\,000) separated by a space, which represent the length of the string SS and the number of queries. The following line contains the string SS, which consists only of ‘(' and ‘)', and whose length is NN. Each of the next QQ lines contains three integers t_it\_i, l_il\_i and r_ir\_i(1t_i21 ≤ t\_i ≤ 2, 1l_ir_iN1 ≤ l\_i ≤ r\_i ≤ N) separated by a space, which represent the ii-th query. It is guaranteed that there is at least one query with t_i=2t\_i = 2.

출력

For each query in the format “22 ll rr", print the value of Ryan's sadness, followed by a newline.