QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 2048 MB 總分: 100

#8771. 二面体群

统计

在数学中,二面体群 $D_n$ 是正 $n$ 边形的对称群。旋转和反射是 $D_n$ 的元素,事实上,二面体群的所有元素都可以表示为一系列旋转和反射的组合。$D_n$ 的元素通过置换顶点来作用于 $n$ 边形。例如,考虑一个正五边形,其顶点初始标记为 1, 3, 5, 4, 2(从顶部开始,顺时针方向):

对该五边形应用上述三种二面体作用(一次旋转、一次反射,然后再进行一次旋转)会产生以下顶点重标记: $1, 3, 5, 4, 2 \to 2, 1, 3, 5, 4 \to 2, 4, 5, 3, 1 \to 4, 5, 3, 1, 2$。

给定一个正 $n$ 边形顶点的任意顺时针标记(使用 1 到 $n$ 的整数),以及一个待测试的序列。请确定是否可以通过对该 $n$ 边形应用一系列二面体作用,使得测试序列出现在变换后多边形的顶点标签的连续顺时针序列中。

输入格式

输入的第一行包含两个整数 $n$ 和 $m$ ($1 \le m \le n \le 5 \cdot 10^4$),其中 $n$ 是多边形的顶点数,$m$ 是待测试序列的长度。

下一行包含 $n$ 个空格分隔的整数 $d$ ($1 \le d \le n$)。这是多边形顶点的初始标记。保证 1 到 $n$ 的每个整数恰好出现一次。

下一行包含 $m$ 个空格分隔的整数 $t$ ($1 \le t \le n$)。这是待测试的序列。

输出格式

输出一个整数,如果测试序列可以在对初始多边形应用某些二面体作用后作为顶点标签的连续序列出现,则输出 1,否则输出 0。

样例

输入 1

3 3
1 2 3
1 3 2

输出 1

1

输入 2

3 1
1 2 3
1

输出 2

1

输入 3

4 2
1 2 3 4
1 3

输出 3

0

输入 4

4 4
1 2 3 4
2 3 4 1

输出 4

1

输入 5

4 4
1 2 3 4
3 2 1 4

输出 5

1

输入 6

5 3
1 3 5 4 2
2 1 3

输出 6

1

输入 7

5 4
1 3 5 4 2
2 1 5 3

输出 7

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.