結果

問題 No.3503 Brackets Stack Query 2
コンテスト
ユーザー V_Melville
提出日時 2026-04-17 22:43:53
言語 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
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 1,673 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,357 ms
コンパイル使用メモリ 334,376 KB
実行使用メモリ 12,452 KB
最終ジャッジ日時 2026-04-17 22:44:14
合計ジャッジ時間 11,079 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;

struct Action {
    int type;     
    bool bad_prev; 
};

int main() {
    cin.tie(nullptr) -> sync_with_stdio(false);
    
    int q;
    cin >> q;

    vector<int> st;         
    vector<Action> hist;    
    bool bad = false;

    rep(qi, q) {
        int t;
        cin >> t;

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

            Action act;
            act.bad_prev = bad;
            act.type = 3;

            if (c == '(') {
                st.push_back(0);
                act.type = 0;
            }
            else if (c == '|') {
                if (st.size() and st.back() == 0) {
                    st.back() = 1;
                    act.type = 1;
                }
                else {
                    bad = true;
                }
            }
            else { 
                if (st.size() and st.back() == 1) {
                    st.pop_back();
                    act.type = 2;
                }
                else {
                    bad = true;
                }
            }

            hist.push_back(act);
        }
        else {
            Action act = hist.back();
            hist.pop_back();

            bad = act.bad_prev;

            if (act.type == 0) {
                st.pop_back();
            }
            else if (act.type == 1) {
                st.back() = 0;
            }
            else if (act.type == 2) {
                st.push_back(1);
            }
        }
        
        if (!bad and !st.size()) puts("Yes"); else puts("No");
    }
    
    return 0;
}
0