#include #include #include using namespace std; // 最大クエリ数に応じた配列サイズ const int MAXQ = 800005; char st[MAXQ]; // 簡約化されたスタック int pos[MAXQ]; // 文字列Sの各文字がスタックのどこに対応するかを記録 char raw_s[MAXQ]; // 文字列Sそのものを記録 int main() { // 高速入出力 ios::sync_with_stdio(false); cin.tie(nullptr); int Q; cin >> Q; int current_s_len = 0; // 現在の文字列Sの長さ int st_ptr = 0; // 簡約スタックの現在のポインタ for (int i = 0; i < Q; ++i) { int type; cin >> type; if (type == 1) { char c; cin >> c; current_s_len++; raw_s[current_s_len] = c; // 簡約スタックに文字を追加 st[st_ptr] = c; st_ptr++; // 末尾が (|) になったらスタックポインタを3つ戻す if (st_ptr >= 3 && st[st_ptr - 3] == '(' && st[st_ptr - 2] == '|' && st[st_ptr - 1] == ')') { st_ptr -= 3; } // 現在のSの長さにおける「スタックの深さ」を保存 pos[current_s_len] = st_ptr; } else { // クエリ2: Sの末尾を削除 current_s_len--; // 文字列Sが短くなったので、スタックのポインタを // 「短くなった後のSの末尾」が指していた位置に戻す st_ptr = pos[current_s_len]; } // 簡約スタックが空なら Yes if (st_ptr == 0) { cout << "Yes\n"; } else { cout << "No\n"; } } return 0; }