#abc344e. E - Insert or Erase
E - Insert or Erase
Score: points
问题描述
给定一个长度为 的序列 ,其中 的元素各不相同。
按照给出的顺序处理 个查询。每个查询属于以下两种类型之一:
1 x y
:在 中元素 后立即插入元素 。确保在给出此查询时, 存在于 中。2 x
:从 中移除元素 。确保在给出此查询时, 存在于 中。
保证在处理每个查询后, 非空,并且其元素仍然各不相同。
在处理完所有查询后,打印出 。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a sequence of length . The elements of are distinct.
Process queries in the order they are given. Each query is of one of the following two types:
1 x y
: Insert immediately after the element in . It is guaranteed that exists in when this query is given.2 x
: Remove the element from . It is guaranteed that exists in when this query is given.
It is guaranteed that after processing each query, will not be empty, and its elements will be distinct.
Print after processing all the queries.
Constraints
- For queries of the first type, .
- When a query of the first type is given, exists in .
- For queries of the second type, .
- When a query of the second type is given, exists in .
- After processing each query, is not empty, and its elements are distinct.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Here, represents the -th query and is given in one of the following formats:
Output
Let be the sequence after processing all the queries. Print in this order, separated by spaces.
Sample Input 1
4
2 1 4 3
4
2 1
1 4 5
2 2
1 5 1
Sample Output 1
4 5 1 3
The queries are processed as follows:
- Initially, .
- The first query removes , making .
- The second query inserts immediately after , making .
- The third query removes , making .
- The fourth query inserts immediately after , making .
Sample Input 2
6
3 1 4 5 9 2
7
2 5
1 3 5
1 9 7
2 9
2 3
1 2 3
2 4
Sample Output 2
5 1 7 2 3