結果

問題 No.3652 Range Bracket Sequence
コンテスト
ユーザー あるふぁ
提出日時 2026-09-18 07:26:57
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 811 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,514 ms
コンパイル使用メモリ 192,440 KB
実行使用メモリ 12,544 KB
最終ジャッジ日時 2026-09-18 07:27:14
合計ジャッジ時間 15,241 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other AC * 2 WA * 34 RE * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <atcoder/segtree>
using namespace std;
using namespace atcoder;

struct S{
    int l, r, lr;
};
S op(S l, S r){
    return{
        l.l-min(l.l, r.r)+r.l,
        l.r+r.r-min(l.l, r.r),
        l.lr+r.lr+min(l.l, r.r)
    };
}
S e(){
    return{
        0, 0, 0
    };
}

int main(){
    int N, Q;
    string T;
    cin >> N >> Q >> T;
    segtree<S, op, e> seg(N);
    for (int i = 0; i < N; i++){
        seg.set(i, S{T[i] == '(', T[i] == ')', 0});
    }

    while (Q--){
        int t;
        cin >> t;
        if (t == 1){
            int i, x;
            cin >> i >> x;
            seg.set(i, S{x == 1, x == 2, 0});
        }
        else{
            int l, r;
            cin >> l >> r;
            cout << seg.prod(l-1, r).lr << endl;
        }
    }
}
0