QOJ.ac

QOJ

実行時間制限: 2.0 s メモリ制限: 256 MB 満点: 100 ハック可能 ✓

#17743. 多重集

統計

Busy Beaver 喜歡資料結構問題,但他認為陣列上的區間查詢資料結構問題很無聊。因此,他想出了一種不同類型的資料結構問題,這次是關於多重集 (multisets)

有一個序列 $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$;否則,將 $K$ 個 $M$ 加入 $S$ 中。
  • 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.