QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 256 MB 満点: 100

#966. 増加または減少

統計

サイズ $n$ の2つの順列 $A$ と $B$ が与えられます。どちらの順列も $1$ から $n$ までの整数を含んでいます。以下の種類の操作を $n$ 回以内行って、$A$ を $B$ に変換してください。

  • $A$ の部分区間 $[l, r]$ を選び、昇順または降順に並び替える。

操作回数を最小化する必要はありません。$n$ 回以下の長さの操作手順であればどのようなものでも構いません。

入力

入力は以下の形式で与えられます。

$n$ $A_1, A_2, \dots, A_n$ $B_1, B_2, \dots, B_n$

$n$ ($1 \le n \le 500$) は順列のサイズです。

出力

最初の行に操作回数 $m$ ($0 \le m \le n$) を出力してください。

続く $m$ 行に操作の内容を出力してください。各操作は $l_i \ r_i \ t_i$ ($1 \le l_i \le r_i \le n$, $t_i$ は 'I' または 'D') の形式で出力してください。これは、部分区間 $[l_i, r_i]$ を (I)昇順または (D)降順に並び替えることを意味します。

複数の解が存在する場合、どれを出力しても構いません。少なくとも1つの解が存在することが保証されています。

入出力例

入力 1

5
2 4 5 1 3
5 4 3 2 1

出力 1

1
1 5 D

入力 2

5
5 4 3 2 1
3 2 5 1 4

出力 2

4
2 5 I
1 4 I
1 3 D
3 4 D

入力 3

5
3 1 4 5 2
3 1 4 5 2

出力 3

0

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.