結果

問題 No.1802 Range Score Query for Bracket Sequence
ユーザー ForestedForested
提出日時 2022-01-07 12:17:29
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 784 bytes
コンパイル時間 644 ms
コンパイル使用メモリ 69,144 KB
最終ジャッジ日時 2025-01-27 08:59:23
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 10 TLE * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string>
#include <iostream>

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

int main() {
    std::size_t n, q;
    std::cin >> n >> q;
    std::string s;
    std::cin >> s;
    
    for (std::size_t qi = 0; qi < q; ++qi) {
        std::size_t type;
        std::cin >> type;
        if (type == 1) {
            std::size_t i;
            std::cin >> i;
            --i;
            s[i] ^= '(' ^ ')';
        } else {
            std::size_t l, r;
            std::cin >> l >> r;
            --l;
            std::size_t ans = 0;
            for (std::size_t i = l; i < r - 1; ++i) {
                if (s[i] == '(' && s[i + 1] == ')') {
                    ++ans;
                }
            }
            std::cout << ans << '\n';
        }
    }
}
0