結果

問題 No.1802 Range Score Query for Bracket Sequence
ユーザー 👑 NachiaNachia
提出日時 2022-01-07 22:29:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 1,214 bytes
コンパイル時間 797 ms
コンパイル使用メモリ 77,984 KB
実行使用メモリ 4,408 KB
最終ジャッジ日時 2023-09-12 14:12:10
合計ジャッジ時間 3,524 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 62 ms
4,376 KB
testcase_02 AC 61 ms
4,380 KB
testcase_03 AC 61 ms
4,376 KB
testcase_04 AC 61 ms
4,380 KB
testcase_05 AC 62 ms
4,380 KB
testcase_06 AC 61 ms
4,384 KB
testcase_07 AC 61 ms
4,376 KB
testcase_08 AC 61 ms
4,376 KB
testcase_09 AC 61 ms
4,380 KB
testcase_10 AC 62 ms
4,376 KB
testcase_11 AC 57 ms
4,396 KB
testcase_12 AC 57 ms
4,376 KB
testcase_13 AC 58 ms
4,408 KB
testcase_14 AC 68 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <atcoder/fenwicktree>
using namespace std;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(n); i++)





int main(){
    int N,Q; cin >> N >> Q;
    string S; cin >> S;

    atcoder::fenwick_tree<int> A(N);
    rep(i,N-1) if(S[i] == '(' && S[i+1] == ')') A.add(i,1);

    rep(i,Q){
        int t; cin >> t;
        if(t == 2){
            int l,r; cin >> l >> r; l--;
            int ans = A.sum(l,r-1);
            cout << ans << "\n";
        }
        if(t == 1){
            int p; cin >> p; p--;
            if(S[p] == '('){
                if(p != N-1 && S[p+1] == ')') A.add(p, -1);
                S[p] = ')';
                if(p != 0 && S[p-1] == '(') A.add(p-1, 1);
            }
            else if(S[p] == ')'){
                if(p != 0 && S[p-1] == '(') A.add(p-1, -1);
                S[p] = '(';
                if(p != N-1 && S[p+1] == ')') A.add(p, 1);
            }
        }
    }
    return 0;
}


struct ios_do_not_sync{
    ios_do_not_sync(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }
} ios_do_not_sync_instance;
0