結果

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

ソースコード

diff #
raw source code

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

const int N = 800005;

int st[N], par[N], dep[N];
char ch[N];

int main() {
    cin.tie(0)->sync_with_stdio(0);

    int q;
    if (!(cin >> q)) return 0;

    int p = 0;
    st[0] = dep[0] = 0;

    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            char c;
            cin >> c;
            p++;
            int u = st[p - 1];

            if (c == ')' && dep[u] >= 2 && ch[u] == '|' && ch[par[u]] == '(') {
                st[p] = par[par[u]];
            } else {
                st[p] = p;
                ch[p] = c;
                par[p] = u;
                dep[p] = dep[u] + 1;
            }
        } else {
            p--;
        }

        cout << (dep[st[p]] == 0 ? "Yes\n" : "No\n");
    }

    return 0;
}
0