P27681 [洛谷] [CCC 2024 S3] Swipe
提高
题目描述

Problem Description

Swipe is a new popular mobile game. In each level of the Swipe game, you are given two sequences \( A \) and \( B \) of length \( N \). The goal of each level is to transform array \( A \) into array \( B \).

There are two types of sliding operations that can be performed on \( A \):

  • Right Slide: Select an interval \([l, r]\), and for any \( l \leq i \leq r \), set \( A_i = A_l \).
  • Left Slide: Select an interval \([l, r]\), and for any \( l \leq i \leq r \), set \( A_i = A_r \).

For example, if initially \( A = [0, 1, 2, 3, 4, 5] \), performing a right slide on interval \([2, 4]\) changes the sequence to \([0, 1, 2, 2, 2, 5]\). If we perform a left slide on interval \([3, 5]\), the sequence becomes \([0, 1, 2, 5, 5, 5]\). Note that the sequence is zero-indexed.

Unfortunately, the game has some issues and may include levels that cannot be completed. Determine if it is possible to transform array \( A \) into array \( B \). If possible, provide any sequence of sliding operations that transforms \( A \) into \( B \).

Input Format

The first line of input contains a positive integer \( N \), the length of the two sequences.

The second line contains \( N \) space-separated integers from sequence \( A \).

The third line contains \( N \) space-separated integers from sequence \( B \).

Output Format

If there exists an operation sequence that transforms \( A \) into \( B \), output YES on the first line; otherwise, output NO.

If YES is output on the first line, the next line should contain a non-negative integer \( K \) (\( K \leq N \)) representing the number of slides.

The following \( K \) lines should each contain three space-separated numbers \( D_j, l_j, \) and \( r_j \). \( D_j \) is either R or L, indicating whether the \( j \)-th operation is a right slide or a left slide.

\( l_j \) and \( r_j \) represent the left and right endpoints of the slide operation, and must satisfy \( 0 \leq l_j \leq r_j < N \).

Sample Input and Output

Sample Input #1

3
3 1 2
3 1 1

Sample Output #1

YES
1
R 1 2

Sample Input #2

4
1 2 4 3
1 4 2 3

Sample Output #2

NO

Sample Input #3

4
2 1 4 3
2 1 4 3

Sample Output #3

YES
0

Notes/Hints

This problem uses subtask scoring.

For all data, it is guaranteed that \( 1 \leq N \leq 3 \times 10^5 \) and \( 1 \leq A_i, B_i \leq 3 \times 10^5 \).

The following table shows the scoring distribution:

Score Range of \( N \) Range of \( A_i \) and \( B_i \)
\( 2 \) \( N = 2 \) \( 1 \leq A_i, B_i \leq 3 \)
\( 4 \) \( 1 \leq N \leq 8 \) \( 1 \leq A_i, B_i \leq 8 \)
\( 4 \) \( 1 \leq N \leq 500 \) \( 1 \leq A_i, B_i \leq 3000 \)
\( 5 \) \( 1 \leq N \leq 3 \times 10^5 \) \( 1 \leq A_i, B_i \leq 3 \times 10^5 \)

Note that for a subtask worth \( M \) points, if you only answer the first line correctly, you can get \( \left\lfloor \frac{M}{2} \right\rfloor \) points.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 3 1 2 3 1 1
样例输出
YES 1 R 1 2