P29065 [洛谷] [SEERC2018] Min Max Convert
入门
题目描述

Problem Description

$A$ is a sequence with $N$ elements. You can perform the following two operations on this sequence:

  1. Select an index interval $[a, b] \ (1 \leq a \leq b \leq N)$, let $x$ be the maximum value of the elements in this index interval, and replace all elements in this index interval with $x$.
  2. Select an index interval $[a, b] \ (1 \leq a \leq b \leq N)$, let $x$ be the minimum value of the elements in this index interval, and replace all elements in this index interval with $x$.

Calculate a set of operation schemes to transform sequence $A$ into another given sequence $B$ (also with $N$ elements). The number of operations in the scheme must be less than or equal to $2N$.

Input Format

The first line contains an integer $N$.

The second line contains a sequence $A$ with $N$ elements.

The third line contains another sequence $B$ with $N$ elements.

Output Format

If there is no solution, output $-1$. Otherwise, output an integer $x$ on the first line, representing the minimum number of operations required to transform sequence $A$ into $B$. The next $x$ lines should each contain a character (representing the type of operation, m for using the minimum value operation, M for using the maximum value operation) and an interval $(a, b)$, describing the required operation information. If there are multiple solutions, any one will suffice.

Sample Input and Output

Sample Input #1

5
1 5 5 3 4
1 1 4 4 4

Sample Output #1

3
m 1 2
M 4 5
m 3 5

Sample Input #2

5
1 2 3 4 4
2 2 2 2 5

Sample Output #2

-1

Notes

  • $1 \leq N \leq 100,000$
  • The elements in sequences $A$ and $B$ are integers in the range $[1, N]$
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
5 1 5 5 3 4 1 1 4 4 4
样例输出
3 m 1 2 M 4 5 m 3 5