#P10297. [CCC 2024 S3] Swipe

    ID: 11622 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2024Special JudgeCCC(加拿大)构造

[CCC 2024 S3] Swipe

Problem Description

Swipe is a new mobile game that has recently become very popular. In each level of Swipe, you are given two sequences AA and BB of length NN. The goal of each level is to turn array AA into array BB.

There are now two types of swipe operations that can be applied to AA.

  • Swipe right: choose an interval [l,r][l, r], and for every lirl \leq i \leq r, set Ai=AlA_i = A_l.
  • Swipe left: choose an interval [l,r][l, r], and for every lirl \leq i \leq r, set Ai=ArA_i = A_r.

For example, initially A=[0,1,2,3,4,5]A = [0, 1, 2, 3, 4, 5]. If we perform a swipe right on interval [2,4][2, 4], the sequence becomes [0,1,2,2,2,5][0, 1, 2, 2, 2, 5]. If we perform a swipe left on interval [3,5][3, 5], the sequence becomes [0,1,2,5,5,5][0, 1, 2, 5, 5, 5]. Note that the sequence is indexed starting from 00.

Unfortunately, the game has some issues and may contain levels that cannot be cleared. Determine whether it is possible to transform array AA into array BB. If it is possible, output any sequence of swipe operations that transforms AA into BB.

Input Format

The first line contains a positive integer NN, the length of the two sequences.

The second line contains NN integers from AA, separated by spaces.

The third line contains NN integers from BB, separated by spaces.

Output Format

If there exists a sequence of operations that can turn AA into BB, output YES on the first line; otherwise output NO.

If you output YES on the first line, then the next line contains a non-negative integer KK (KNK \leq N), the number of swipes.

In the next KK lines, each line contains three space-separated values: DjD_j, ljl_j, and rjr_j. DjD_j is R or L, indicating whether the jj-th operation is a swipe right or a swipe left.

ljl_j and rjr_j are the left and right endpoints of the swipe, and must satisfy 0ljrj<N0 \leq l_j \leq r_j < N.

3
3 1 2
3 1 1

YES
1
R 1 2

4
1 2 4 3
1 4 2 3

NO

4
2 1 4 3
2 1 4 3

YES
0

Hint

This problem uses bundled testdata.

For all testdata, it is guaranteed that 1N3×1051 \leq N \leq 3 \times 10^5, and 1Ai,Bi3×1051 \leq A_i, B_i \leq 3 \times 10^5.

The following table shows the distribution of the 1515 points:

Points Range of NN Range of AiA_i and BiB_i
22 N=2N = 2 1Ai,Bi31 \leq A_i, B_i \leq 3
44 1N81 \leq N \leq 8 1Ai,Bi81 \leq A_i, B_i \leq 8
1N5001 \leq N \leq 500 1Ai,Bi30001 \leq A_i, B_i \leq 3000
55 1N3×1051 \leq N \leq 3 \times 10^5 1Ai,Bi3×1051 \leq A_i, B_i \leq 3 \times 10^5

Note that for a subtask worth MM points, if you only answer the first line correctly, you can get M2\left\lfloor\dfrac M2\right\rfloor points.

Translated by ChatGPT 5