結果

問題 No.3652 Range Bracket Sequence
コンテスト
ユーザー yuunegi
提出日時 2026-08-28 22:00:06
言語 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  
実行時間 288 ms / 2,000 ms
+ 562µs
コード長 1,082 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,172 ms
コンパイル使用メモリ 377,700 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2026-08-28 22:01:23
合計ジャッジ時間 15,231 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 57
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
#if __has_include("all.hpp")
#include "all.hpp"
#else
#include <atcoder/all>
#endif
using namespace atcoder;
struct S{
    int ans,rr,rl;
};
S op(S a, S b) {
    S tmp;
    tmp.ans=a.ans+b.ans;
    tmp.rr=b.rr;
    tmp.rl=a.rl;
    if(a.rr<=b.rl){
        tmp.ans+=a.rr;
        tmp.rl+=b.rl-a.rr;
    }else{
        tmp.ans+=b.rl;
        tmp.rr+=a.rr-b.rl;
    }
    return tmp;
}
S e() { return {0,0,0}; }
int main(void){
    int n,q;
    cin>>n>>q;
    string s;
    cin>>s;
    vector<S>si(n);
    for(int i=0;i<n;i++){
        if(s[i]=='('){
            si[i].rr++;
        }else{
            si[i].rl++;
        }
    }
    segtree<S, op, e> seg(si);
    while(q--){
        int o;
        cin>>o;
        if(o==1){
            int x,t;
            cin>>x>>t;
            if(t==1){
                seg.set(x-1,{0,1,0});
            }else{
                seg.set(x-1,{0,0,1});
            }
        }else{
            int r,l;
            cin>>r>>l;
            cout<<seg.prod(r-1,l).ans*2<<endl;
        }
    }
    return 0;
}
0