아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Increasing or Decreasing

시간 제한1초메모리 제한256 MB

요약
순열 A를 순열 B로 바꾸는 문제로, 구간을 오름차순이나 내림차순으로 정렬하는 연산을 n번 이하로 사용해야 합니다.
난이도

보통10점 중 7점

유형
정렬, 구현, 그리디
정답자
아직 제출이 없습니다

문제

You are given two permutations AA and BB of size nn. You want to transform AA to BB in no more than nn operations of the following kind:

  • Choose a subsegment \[l;r]\[l;r] of AA and sort it in either increasing or decreasing order.

Note that you don't have to minimize the number of operations, any sequence of operations of length not more than nn is ok.

입력

The first line contains one integer nn (1≤n≤5001 \le n \le 500) --- the sizes of both permutations.

The second line contains the permutation A_1,A_2,…,A_nA\_{1}, A\_{2}, \ldots, A\_{n}.

The third line contains the permutation B_1,B_2,…,B_nB\_{1}, B\_{2}, \ldots, B\_{n}.

출력

On the first line print one integer mm (0≤m≤n0 \le m \le n) --- the number of operations.

On the next mm lines print the descriptions of operation. One description has a form l_il\_{i} r_ir\_{i} t_it\_{i}  (1≤l_i≤r_i≤n1 \le l\_{i} \le r\_{i} \le n, t_it\_{i} is 'I' or 'D') and means sort the subsegment \[l_i;r_i]\[l\_{i};r\_{i}] in (I)ncreasing or (D)ecreasing order.

If there are different solutions any one will be accepted. It is guaranteed that there is at least one solution.

예제3

  1. 예제 1

    입력
    5
    2 4 5 1 3
    5 4 3 2 1
    
    예상 출력
    1
    1 5 D
    
  2. 예제 2

    입력
    5
    5 4 3 2 1
    3 2 5 1 4
    
    예상 출력
    4
    2 5 I
    1 4 I
    1 3 D
    3 4 D
    
  3. 예제 3

    입력
    5
    3 1 4 5 2
    3 1 4 5 2
    
    예상 출력
    0