QOJ.ac

QOJ

Límite de tiempo: 2 s Límite de memoria: 64 MB Puntuación total: 100

#14954. 匹配

Estadísticas

作为新广告宣传活动的一部分,格丁尼亚(Gdynia)的一家大公司希望在城市的某个地方展示其标志(logo)。该公司打算将今年的全部广告预算都花在这个标志上,因此它必须非常巨大。其中一位经理决定将整栋建筑物作为标志的一部分。

该标志由 $n$ 条不同高度的垂直条纹组成。条纹从左到右依次编号为 $1$ 到 $n$。该标志由数字 $1, 2, \dots, n$ 的一个排列 $(s_1, s_2, \dots, s_n)$ 来描述。条纹 $s_1$ 是最短的,条纹 $s_2$ 是第二短的,依此类推,最后条纹 $s_n$ 是最高的。条纹的实际高度并不重要,重要的是它们的相对大小。

格丁尼亚的主街旁有 $m$ 栋建筑物。令你惊讶的是,这些建筑物的高度各不相同。任务是找到所有标志与建筑物相匹配的位置。

帮助该公司找到建筑物序列中所有与标志相匹配的连续子序列。如果一个连续的建筑物序列中,第 $s_1$ 栋建筑物(即该子序列中的第 $s_1$ 栋)是最矮的,第 $s_2$ 栋建筑物是第二矮的,依此类推,则该连续建筑物序列与标志相匹配。例如,高度为 $5, 10, 4$ 的建筑物序列与由排列 $(3, 1, 2)$ 描述的标志相匹配,因为第 $3$ 栋建筑物(高度为 $4$)是最矮的,第 $1$ 栋建筑物(高度为 $5$)是第二矮的,第 $2$ 栋建筑物(高度为 $10$)是最高的。

输入格式

输入第一行包含两个整数 $n$ 和 $m$($2 \le n \le m \le 1\,000\,000$)。

第二行包含 $n$ 个整数 $s_i$,构成数字 $1, 2, \dots, n$ 的一个排列。即 $1 \le s_i \le n$ 且对于 $i \neq j$ 有 $s_i \neq s_j$。

第三行包含 $m$ 个整数 $h_i$ —— 代表建筑物的高度(对于 $1 \le i \le m$,有 $1 \le h_i \le 10^9$)。所有的数字 $h_i$ 互不相同。

每行中的整数之间用单个空格分隔。

输出格式

输出第一行应包含一个整数 $k$,表示匹配的次数。

第二行应包含 $k$ 个整数 —— 在每个匹配中,对应于标志中第 $1$ 号条纹的建筑物的下标(下标从 $1$ 开始)。这些数字应按升序排列,并用单个空格分隔。

如果 $k = 0$,你的程序应输出一个空行作为第二行。

数据范围

对于至少 $35\%$ 的测试数据,满足 $n \le 5\,000$ 且 $m \le 20\,000$。

对于至少 $60\%$ 的测试数据,满足 $n \le 50\,000$ 且 $m \le 200\,000$。

对于 $100\%$ 的测试数据,满足 $2 \le n \le m \le 1\,000\,000$,$1 \le h_i \le 10^9$。

样例

输入样例 1

5 10
2 1 5 3 4
5 6 3 8 12 7 1 10 11 9

输出样例 1

2
2 6

说明

序列 $6, 3, 8, 12, 7$ 和 $7, 1, 10, 11, 9$ 都与由排列 $(2, 1, 5, 3, 4)$ 描述的标志相匹配。特别地,在第一个序列中,第 $2$ 栋建筑物(高度为 $3$)是最矮的,第 $1$ 栋建筑物(高度为 $6$)是第二矮的,第 $5$ 栋建筑物(高度为 $7$)是第三矮的,依此类推。

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.