QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 256 MB 總分: 100

#966. 遞增或遞減

统计

給定兩個大小為 $n$ 的排列 $A$ 與 $B$。這兩個排列皆包含從 $1$ 到 $n$ 的整數。你想要透過不超過 $n$ 次的下列操作將 $A$ 轉換為 $B$:

  • 選擇 $A$ 的一個子區段 $[l; r]$,並將其按遞增或遞減順序排序。

請注意,你不需要最小化操作次數,任何長度不超過 $n$ 的操作序列皆可。

輸入格式

第一行包含一個整數 $n$ ($1 \le n \le 500$),代表兩個排列的大小。 第二行包含排列 $A_1, A_2, \dots, A_n$。 第三行包含排列 $B_1, B_2, \dots, B_n$。

輸出格式

第一行請輸出一個整數 $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

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.