QOJ.ac

QOJ

Límite de tiempo: 0.5 s Límite de memoria: 256 MB Puntuación total: 100

#2387. 最小最大转换

Estadísticas

设 $A$ 是一个包含 $N$ 个元素的序列。你可以对该序列执行两种操作:

  1. 选择一个区间 $[a, b]$ ($1 \le a \le b \le N$)。令 $x$ 为该区间内的最大值。将该区间内的所有元素替换为 $x$。
  2. 选择一个区间 $[a, b]$ ($1 \le a \le b \le N$)。令 $x$ 为该区间内的最小值。将该区间内的所有元素替换为 $x$。

请确定一个操作序列,使得序列 $A$ 变为另一个给定的序列 $B$(同样包含 $N$ 个元素)。操作次数必须小于或等于 $2 * N$。

输入格式

第一行包含一个整数 $N$。第二行包含序列 $A$,由 $N$ 个元素组成。第三行包含序列 $B$,由 $N$ 个元素组成。

输出格式

如果不存在将序列 $A$ 变为 $B$ 的方案,输出 $-1$。否则,在第一行输出一个整数 $x$,表示将序列 $A$ 转换为 $B$ 所需的最少操作次数。接下来的 $x$ 行,每行包含一个字符(操作类型:$m$ 表示使用最小值操作,$M$ 表示使用最大值操作)和一个区间 $(a, b)$,描述转换过程所需的操作。如果存在多种方案,输出其中任意一种即可。

数据范围

  • $1 \le N \le 100\,000$
  • $A$ 和 $B$ 中的所有值均为 $[1, N]$ 范围内的整数

样例

输入 1

5
1 5 5 3 4
1 1 4 4 4

输出 1

3
m 1 2
M 4 5
m 3 5

输入 2

5
1 2 3 4 4
2 2 2 2 5

输出 2

-1

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.