#abc344e. E - Insert or Erase

E - Insert or Erase

Score: 475475 points

问题描述

给定一个长度为 NN 的序列 A=(A1,,AN)A=(A_1,\ldots,A_N),其中 AA 的元素各不相同。

按照给出的顺序处理 QQ 个查询。每个查询属于以下两种类型之一:

  • 1 x y :在 AA 中元素 xx 后立即插入元素 yy。确保在给出此查询时,xx 存在于 AA 中。
  • 2 x :从 AA 中移除元素 xx。确保在给出此查询时,xx 存在于 AA 中。

保证在处理每个查询后,AA 非空,并且其元素仍然各不相同。

在处理完所有查询后,打印出 AA

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a sequence A=(A1,,AN)A=(A_1,\ldots,A_N) of length NN. The elements of AA are distinct.

Process QQ queries in the order they are given. Each query is of one of the following two types:

  • 1 x y : Insert yy immediately after the element xx in AA. It is guaranteed that xx exists in AA when this query is given.
  • 2 x : Remove the element xx from AA. It is guaranteed that xx exists in AA when this query is given.

It is guaranteed that after processing each query, AA will not be empty, and its elements will be distinct.

Print AA after processing all the queries.

Constraints

  • 1N2×1051 \leq N \leq 2\times 10^5
  • 1Q2×1051 \leq Q \leq 2\times 10^5
  • 1Ai1091 \leq A_i \leq 10^9
  • AiAjA_i \neq A_j
  • For queries of the first type, 1x,y1091 \leq x,y \leq 10^9.
  • When a query of the first type is given, xx exists in AA.
  • For queries of the second type, 1x1091 \leq x \leq 10^9.
  • When a query of the second type is given, xx exists in AA.
  • After processing each query, AA 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:

NN

A1A_1 \ldots ANA_N

QQ

Query1\mathrm{Query}_1

\vdots

QueryQ\mathrm{Query}_Q

Here, Queryi\mathrm{Query}_i represents the ii-th query and is given in one of the following formats:

11 xx yy

22 xx

Output

Let A=(A1,,AK)A=(A_1,\ldots,A_K) be the sequence after processing all the queries. Print A1,,AKA_1,\ldots,A_K 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, A=(2,1,4,3)A=(2,1,4,3).
  • The first query removes 11, making A=(2,4,3)A=(2,4,3).
  • The second query inserts 55 immediately after 44, making A=(2,4,5,3)A=(2,4,5,3).
  • The third query removes 22, making A=(4,5,3)A=(4,5,3).
  • The fourth query inserts 11 immediately after 55, making A=(4,5,1,3)A=(4,5,1,3).

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
}