結果

問題 No.3500 01 String
コンテスト
ユーザー R1yhtp
提出日時 2026-04-17 23:54:28
言語 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
結果
RE  
実行時間 -
コード長 1,351 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,132 ms
コンパイル使用メモリ 332,940 KB
実行使用メモリ 7,808 KB
最終ジャッジ日時 2026-04-17 23:54:52
合計ジャッジ時間 4,815 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 10 RE * 10
権限があれば一括ダウンロードができます

ソースコード

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;

    // 题目 Q 约为 8e5,开到 Q+5 足够
    vector<int> parent(Q + 5, 0); // 持久化栈前驱
    vector<int> state(Q + 5, 0);  // state[len] = 当前原串长度为 len 时的化简栈顶
    vector<char> val(Q + 5, 0);   // 当前节点存的字符

    int tot = 0;  // 节点总数
    int len = 0;  // 当前原串长度

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

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

            int cur = state[len];
            int nxt;

            // 只有在化简栈末尾是 "(|" 且新字符是 ')' 时,才能消掉
            if (c == ')' &&
                cur != 0 &&
                val[cur] == '|' &&
                parent[cur] != 0 &&
                val[parent[cur]] == '(') {
                nxt = parent[parent[cur]];  // 消去 "(|)"
            } else {
                ++tot;
                val[tot] = c;
                parent[tot] = cur;
                nxt = tot;
            }

            ++len;
            state[len] = nxt;
        } else {
            // 删除最后一个字符
            --len;
        }

        cout << (state[len] == 0 ? "Yes" : "No") << '\n';
    }

    return 0;
}
0