問題一覧 > 通常問題

No.1802 Range Score Query for Bracket Sequence

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 82
作問者 : NatsubiSogan / テスター : 👑 Forested penguinman
お気に入りにしたユーザー ProblemId : 7244 / 自分の提出
問題文最終更新日: 2021-12-16 21:26:21
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original
yukicoder contest 326 (順位表) の他の問題:

Problem Statement

A symmetric bracket sequence is defined as a non-empty string satisfying one of the following conditions.

  • ()
  • A string obtained by concatenating (, $s$, ) in this order, for some symmetric bracket sequence $s$

Also, for a string $s$ consisting of ( and ), its score is defined as follows.

  • The number of times the following operation can be repeated.
    • Among the contiguous subsequences of $s$ that are symmetric bracket sequences, choose $1$ longest one and delete it.
  • It can be proved that this number is uniquely determined regardless of the order in which the subsequences are removed.

There is a string $S$ of length $N$ consisting of ( and ).

You are given $Q$ queries on $S$; process them in order. There are $2$ types of queries, whose input formats and contents are as follows.

  • 1 i: Change the $i$-th character of $S$ to the one of (, ) that differs from the current character.
  • 2 l r: Output the score of the substring obtained by taking the $l$-th through $r$-th characters of $S$.

Input

$N$ $Q$
$S$
$\mathrm{query}_1$
$\mathrm{query}_2$
$\vdots$
$\mathrm{query}_Q$
  • $N$ is an integer satisfying $1 \leq N \leq 2 \times 10^5$
  • $Q$ is an integer satisfying $1 \leq Q \leq 2 \times 10^5$
  • $S$ is a string of length $N$ consisting of ( and )
  • For queries of the form 1 i, $i$ is an integer satisfying $1 \leq i \leq N$
  • For queries of the form 2 l r, $l, r$ are integers satisfying $1 \leq l \leq r \leq N$
  • Queries of the form 2 l r appear at least $1$ time

Output

For each query of the form 2 l r, output the answer on $1$ line.

Print a newline after each output query $1$.

Sample

Sample 1
Input
5 3
(()))
2 1 4
1 4
2 2 5
Output
1
2
  • For $\mathrm{query}_1$: We find the score of the substring obtained by taking the $1$-st through $4$-th characters of $S$, namely (()). Since this is itself a symmetric bracket sequence, the value is clearly $1$.
  • For $\mathrm{query}_2$: The $4$-th character of $S$ is changed from ) to (, and $S$ becomes (()().
  • For $\mathrm{query}_3$: We find the score of the substring obtained by taking the $2$-nd through $5$-th characters of $S$, namely ()(). This value is $2$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。