結果

問題 No.3652 Range Bracket Sequence
コンテスト
ユーザー shingo0909
提出日時 2026-08-28 22:55:02
言語 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  
実行時間 251 ms / 2,000 ms
+ 476µs
コード長 1,492 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,441 ms
コンパイル使用メモリ 338,352 KB
実行使用メモリ 7,680 KB
最終ジャッジ日時 2026-08-28 22:55:31
合計ジャッジ時間 14,019 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 57
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <atcoder/lazysegtree>
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int op(int a, int b) {
    return min(a, b);
}

int e() {
    return 1 << 30;
}

int mapping(int f, int a) {
    return f + a;
}
int comp(int f, int g) {
    return f + g;
}
int id() {
    return 0;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int n, q;
    string s;
    cin >> n >> q >> s;
    vector<int> v(n + 1, 0);
    rep(i, n) {
        v[i + 1] = v[i];
        if (s[i] == '(')
            v[i + 1]++;
        else
            v[i + 1]--;
    }
    atcoder::lazy_segtree<int, op, e, int, mapping, comp, id> seg(v);
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            int x, t;
            cin >> x >> t;
            x--;
            if (s[x] == '(')
                seg.apply(x + 1, n + 1, -1);
            else
                seg.apply(x + 1, n + 1, 1);
            if (t == 1)
                s[x] = '(';
            else
                s[x] = ')';
            if (s[x] != '(')
                seg.apply(x + 1, n + 1, -1);
            else
                seg.apply(x + 1, n + 1, 1);
        } else {
            int l, r;
            cin >> l >> r;
            l--;
            int L = seg.get(l);
            int R = seg.get(r);
            int M = seg.prod(l, r + 1);
            cout << (r - l - (L + R - 2 * M)) << endl;
        }
    }
    return 0;
}
0