結果

問題 No.3503 Brackets Stack Query 2
コンテスト
ユーザー Azaki
提出日時 2026-04-18 01:43:35
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,270 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,139 ms
コンパイル使用メモリ 158,472 KB
実行使用メモリ 7,552 KB
最終ジャッジ日時 2026-04-18 01:43:46
合計ジャッジ時間 9,988 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 10 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>

using namespace std;

const int MAXQ = 800005;
char st[MAXQ];
int ptr_history[MAXQ]; // Sの長さ L に対する st_ptr の値を保存

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int Q;
    cin >> Q;

    int current_S_len = 0;
    int st_ptr = 0;
    ptr_history[0] = 0;

    for (int i = 0; i < Q; ++i) {
        int type;
        cin >> type;

        if (type == 1) {
            char c;
            cin >> c;
            current_S_len++;
            
            // 前の状態(S_len - 1)の st_ptr を引き継いで新しい文字を処理
            st_ptr = ptr_history[current_S_len - 1];
            st[st_ptr] = c;
            st_ptr++;

            if (st_ptr >= 3 && st[st_ptr-3] == '(' && st[st_ptr-2] == '|' && st[st_ptr-1] == ')') {
                st_ptr -= 3;
            }
            ptr_history[current_S_len] = st_ptr;
        } else {
            // クエリ2: 文字列Sの長さを減らす
            current_S_len--;
            // 次回 type 1 が来た時に ptr_history[current_S_len] から再開される
            st_ptr = ptr_history[current_S_len];
        }

        if (st_ptr == 0) cout << "Yes\n";
        else cout << "No\n";
    }
    return 0;
}
0