QOJ.ac

QOJ

حد الوقت: 2.5 s حد الذاكرة: 1024 MB مجموع النقاط: 100

#11640. 无限数组

الإحصائيات

数组 $B$ 的子数组是取自 $B$ 的连续元素序列。例如,如果 $B = [3, 1, 4, 1, 5]$,则 $[3, 1, 4]$、$[4, 1]$、空数组 $[ ]$ 以及整个数组 $B$ 都是 $B$ 的子数组(除此之外还有其他),而 $[3, 4, 5]$ 和 $[1, 3]$ 则不是 $B$ 的子数组。

我们定义 $C^m$ 为将 $m$ 个数组 $C$ 连接后得到的数组。例如,如果 $C = [3, 2]$,则 $C^1 = [3, 2]$,$C^2 = [3, 2, 3, 2]$ 且 $C^\infty = [\dots, 3, 2, 3, 2, 3, 2, \dots]$。

在本题中,给定一个不包含重复数字的数组 $P$,你需要按顺序处理一系列事件。事件分为以下三种类型:

  • 删除(Delete):必须删除 $P$ 中存在的一个数字。例如,如果 $P = [2, 3, 4]$ 且需要删除数字 $3$,则处理该事件后 $P$ 将变为 $[2, 4]$。
  • 插入(Insert):必须将一个 $P$ 中不存在的数字插入到 $P$ 中某个已存在的数字之前。例如,如果 $P = [4, 3, 2, 1]$ 且需要将数字 $9$ 插入到数字 $1$ 之前,则处理该事件后 $P$ 将变为 $[4, 3, 2, 9, 1]$。
  • 查询(Query):计算 $P^\infty$ 和 $A^\infty$ 之间的最长公共子数组长度,其中 $A$ 是查询中给定的数组。例如,如果 $P = [1, 2, 3, 4]$ 且 $A = [3, 2]$,则 $P^\infty$ 和 $A^\infty$ 之间的最长公共子数组是 $[2, 3]$,因此查询的答案为 $2$。

输入格式

第一行包含一个整数 $N$ ($1 \le N \le 5 \cdot 10^5$),表示 $P$ 的初始长度。 第二行包含 $N$ 个不同的整数 $P_1, P_2, \dots, P_N$ ($1 \le P_i \le 10^6$,对于 $i = 1, 2, \dots, N$)。 第三行包含一个整数 $E$ ($1 \le E \le 5 \cdot 10^5$),表示需要处理的事件数量。 接下来的 $E$ 行按顺序描述了每个事件。行的内容取决于事件类型,如下所示:

  • 删除:该行包含字符 “-” (减号) 和一个整数 $X$ ($1 \le X \le 10^6$ 且 $X \in P$),表示必须从 $P$ 中删除 $X$。保证删除后 $P$ 不会变为空。
  • 插入:该行包含字符 “+” (加号) 和两个整数 $Y$ 和 $Z$ ($1 \le Y, Z \le 10^6$,$Y \notin P$ 且 $Z \in P$),表示必须将 $Y$ 插入到 $P$ 中 $Z$ 的紧左侧。
  • 查询:该行包含字符 “?” (问号)、一个正整数 $K$ 以及 $K$ 个整数 $A_1, A_2, \dots, A_K$ ($1 \le A_i \le 10^6$,对于 $i = 1, 2, \dots, K$),表示需要计算 $P^\infty$ 和 $A^\infty$ 之间的最长公共子数组长度。保证输入中至少包含一个查询,且所有查询的 $K$ 之和不超过 $10^6$。

输出格式

对于每个查询,输出一行,包含一个整数,表示 $P^\infty$ 和 $A^\infty$ 之间的最长公共子数组长度;如果最长公共子数组的长度大于 $10^{18}$,则输出字符 “*” (星号)。

样例

样例输入 1

4
1 2 3 4
10
? 2 3 2
? 3 99 99 99
- 1
- 4
? 2 3 3
? 3 4 1 4
+ 64 3
+ 1 2
? 4 1 2 64 3
? 4 1 3 64 2

样例输出 1

2
0
1
0
*
1

样例输入 2

1
217
1
? 1 314

样例输出 2

0

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.