QOJ.ac

QOJ

时间限制: 2.0 s 内存限制: 256 MB 总分: 100 可 Hack ✓

#17743. 多重集

统计

Busy Beaver 喜欢数据结构题,但他认为数组上的区间查询数据结构题很无聊。于是他想出了另一种数据结构题,这次是关于多重集的!

有一个序列 $a_1, \dots, a_L$,其中每个 $a_i$ 都是一个正整数多重集。初始时序列为空,即 $L=0$。请实现以下操作:

  • 1 M K:在序列末尾添加一个仅包含 $K$ 个 $M$ 的多重集。
  • 2 X Y:在序列末尾添加 $a_X$ 和 $a_Y$ 的。每个数值出现的次数相加;例如,我们将多重集 $\{1, 1, 2\}$ 和 $\{1, 2\}$ 的和定义为 $\{1, 1, 1, 2, 2\}$。
  • 3 X M K:在序列末尾添加 $f(a_X,M,K)$,其中 $f(S,M,K)$ 的定义为:如果 $S$ 中至少有 $K$ 个 $M$,则从 $S$ 中移除 $K$ 个 $M$;否则,向 $S$ 中添加 $K$ 个 $M$。
  • 4 X保证 $a_X$ 仅包含一个元素。 输出 $a_X$ 中的这个元素。

输入格式

第一行包含一个整数 $Q$ ($1 \le Q \le 5 \cdot 10^5$),表示操作次数。

接下来的 $Q$ 行,每行包含一个操作。

保证:

  • 操作 $2$、$3$ 和 $4$ 中使用的下标 $X$ 和 $Y$ 在操作时始终在序列范围内。
  • 操作 $1$ 和 $3$ 中使用的数值 $M$ 和 $K$ 满足 $1 \le M,K \le 10^9$。
  • 对于所有类型 $4$ 的操作,$a_X$ 恰好包含一个元素。

输出格式

对于每个类型 $4$ 的操作,输出一行答案。

子任务

  • ($10$ 分) 对于所有类型 $1$ 和 $3$ 的操作,$1 \le M \le 10$。
  • ($40$ 分) 保证在每个类型 $3$ 的操作中,新添加的多重集都是通过从 $a_X$ 中移除 $K$ 个 $M$ 形成的。
  • ($50$ 分) 无附加限制。

样例

样例输入 1

8
1 5 1
1 6 2
4 1
2 1 2
3 3 6 4
3 4 6 5
3 5 5 1
4 6

样例输出 1

5
6

说明

多重集如下:

  • $a_1 = \{5\}$。
  • $a_2 = \{6, 6\}$。
  • $a_3 = \{5, 6, 6\}$。
  • $a_4 = \{5, 6, 6, 6, 6, 6, 6\}$。
  • $a_5 = \{5, 6\}$。
  • $a_6 = \{6\}$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.