結果

問題 No.3503 Brackets Stack Query 2
コンテスト
ユーザー Qiu Tian
提出日時 2026-04-18 15:09:06
言語 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,336 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,502 ms
コンパイル使用メモリ 342,800 KB
実行使用メモリ 65,064 KB
最終ジャッジ日時 2026-04-18 15:09:16
合計ジャッジ時間 7,718 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other AC * 5 WA * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

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

    int Q;
    cin >> Q;

    vector<vector<int>> stk_hist;
    vector<bool> bad_hist;

    vector<int> stk; // stack of pipe counts
    bool bad = false;

    stk_hist.push_back(stk);
    bad_hist.push_back(bad);

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

        if (t == 1) {
            char c;
            cin >> c;

            if (!bad) {
                if (c == '(') {
                    stk.push_back(0);
                } 
                else if (c == '|') {
                    if (stk.empty()) bad = true;
                    else stk.back()++;
                } 
                else { // ')'
                    if (stk.empty() || stk.back() != 1) bad = true;
                    else stk.pop_back();
                }
            }
        } else {
            stk = stk_hist.back();
            bad = bad_hist.back();
            stk_hist.pop_back();
            bad_hist.pop_back();
            // after popping, continue to output
            cout << (!bad && stk.empty() ? "Yes\n" : "No\n");
            continue;
        }

        stk_hist.push_back(stk);
        bad_hist.push_back(bad);

        cout << (!bad && stk.empty() ? "Yes\n" : "No\n");
    }

    return 0;
}
0