結果

問題 No.3652 Range Bracket Sequence
コンテスト
ユーザー tau1235
提出日時 2026-08-28 21:55:04
言語 C++23
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 297 ms / 2,000 ms
+ 589µs
コード長 743 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,424 ms
コンパイル使用メモリ 337,752 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2026-08-28 21:55:45
合計ジャッジ時間 13,221 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 57
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
#include<atcoder/segtree>
using namespace std;

struct S{
  int cl=0,cr=0;
  int cnt=0;
};
S op(S a,S b){
  a.cnt+=b.cnt;
  int p=min(a.cl,b.cr);
  a.cnt+=p;
  a.cl+=b.cl-p;
  a.cr+=b.cr-p;
  return a;
}
S e(){return S{0,0,0};}

int main(){
  int n,q;
  string s;
  cin>>n>>q>>s;
  atcoder::segtree<S,op,e> seg(n);
  auto f=[&](char c){
    if (c=='(') return S{1,0,0};
    if (c==')') return S{0,1,0};
    return e();
  };
  for (int i=0;i<n;i++) seg.set(i,f(s[i]));
  while (q--){
    int t;
    cin>>t;
    if (t==1){
      int x,t;
      cin>>x>>t;
      x--;
      seg.set(x,f(s[x]=(t==1?'(':')')));
    }
    if (t==2){
      int l,r;
      cin>>l>>r;
      l--;
      cout<<seg.prod(l,r).cnt*2<<endl;
    }
  }
}
0