import sys def solve(): input_data = sys.stdin.read().splitlines() if not input_data: return q = int(input_data[0]) parent = [0] * (q + 1) char_at = [""] * (q + 1) depth = [0] * (q + 1) current_top = 0 node_count = 0 current_history = [0] * (q + 1) results = [] for i in range(1, q + 1): line = input_data[i] if line[0] == '1': c = line[2] is_match = False if c == ')' and depth[current_top] >= 2: mid_node = current_top top_node = parent[mid_node] if char_at[mid_node] == '|' and char_at[top_node] == '(': current_top = parent[top_node] is_match = True if not is_match: node_count += 1 char_at[node_count] = c parent[node_count] = current_top depth[node_count] = depth[current_top] + 1 current_top = node_count current_history[i] = current_top else: current_top = current_history[i-1] # S'den silme işlemi yapıldığı için bir önceki S durumuna dönülür. # Ancak silinen karakterin stack'te neyi temsil ettiğini bilmek için # S'in uzunluğunu takip eden bir yapı gerekir. # Bu yüzden Query 2'de bir önceki 'S' adımındaki stack tepesine döneriz. # Ama soruda 'S' dizisi değiştiği için i-2. adımdaki stack durumuna dönülür: # S'in son halini takip eden bir liste: pass # Query 2 için daha stabil bir S takibi eklenmiş hali: s_stack_tops = [0] for i in range(1, q + 1): line = input_data[i] if line[0] == '1': c = line[2] prev_top = s_stack_tops[-1] new_top = prev_top matched = False if c == ')' and depth[prev_top] >= 2: mid = prev_top top = parent[mid] if char_at[mid] == '|' and char_at[top] == '(': new_top = parent[top] matched = True if not matched: node_count += 1 char_at[node_count] = c parent[node_count] = prev_top depth[node_count] = depth[prev_top] + 1 new_top = node_count s_stack_tops.append(new_top) else: if len(s_stack_tops) > 1: s_stack_tops.pop() if s_stack_tops[-1] == 0: results.append("Yes") else: results.append("No") sys.stdout.write("\n".join(results) + "\n") if __name__ == "__main__": solve()