QOJ.ac

QOJ

Time Limit: 0.1 s Memory Limit: 512 MB Total points: 100

#7960. 排序大师

統計

题目描述

由于你是排序大师,你经常被路过的游客刁难,要求用一些奇怪的操作给序列排序。

由于你是远近闻名的排序大师,邻国的排序萌新小 I 慕名前来拜访,留下了一个长度为 $n$ 的排列 $a_1, a_2 \cdots, a_n$,并要求你用以下操作将排列升序排序:

  • 定义 $a_{i \sim j} = \{a_i,a_{i+1},\cdots, a_j\}$。选定 $1 \le i \le j < k \le l \le n$,交换 $a_{i \sim j}$ 和 $a_{k \sim l}$,即交换过后序列变为 $a_{1 \sim i-1}, a_{k \sim l}, a_{j+1 \sim k-1}, a_{i \sim j}, a_{l+1 \sim n}$。

由于你是因精益求精而远近闻名的排序大师,你需要给出一个排序方案最小化操作次数。

输入格式

从标准输入读入数据。

输入的第一行一个整数 $n(1 \le n \le 2,000)$ 表示序列长度,第二行 $n$ 个整数 $a_1,a_2,\cdots,a_n (1 \le a_i \le n)$ 描述排列。

输出格式

输出到标准输出。

输出的第一行一个整数 $s$ 表示你给出的方案的步数,接下来 $s$ 行每行四个整数 $i,j,k,l$ 表示一次操作。若有多个方案,输出任意一个即可。

样例1输入

6
1 4 5 3 2 6

样例1输出

1
2 3 5 5

样例1解释

选定 $i = 2, j = 3, k = 5, l = 5$,${1\;{\color{blue}{4\;5}}\;3\;{\color{red}{2}}\;6}$ 变为 $1\;{\color{red}{2}}\;3\;{\color{blue}{4\;5}}\;6$。

Discussions

About Discussions

The discussion section is only for posting: Editorials, 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. Submitting multiple issues may cause your account to be banned.
  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.