QOJ.ac

QOJ

実行時間制限: 10 s メモリ制限: 512 MB 満点: 100 インタラクティブ

#2877. 不精确的排列排序

統計

这是一个交互式问题。

有一个隐藏的整数排列 $a[1], a[2], \dots, a[n]$,其中包含从 $1$ 到 $n$ 的整数。

你的任务是通过比较和交换元素对,将该排列按升序排序。这个问题本可以很简单,但负责该问题的评委过于专注于 G 题和 J 题中的浮点数运算,实现了一个“不精确”的比较器:

  • 如果 $\frac{|a[i]-a[j]|}{\max(a[i],a[j])} \le 0.01$,则返回 $0$;
  • 否则,如果 $a[i] < a[j]$,则返回 $-1$;
  • 否则,返回 $1$。

你的程序可以进行查询,使用此比较器比较任意两个元素,或者交换任意两个元素。每次交换后,程序会被告知排列是否已变为有序。

请在不超过 $300\,000$ 次查询内,对大小最大为 $16\,384$ 的排列进行排序。

交互

首先从评测程序接收一个整数 $n$ —— 排列的大小 ($1 \le n \le 16\,384$)。然后打印查询并从评测程序接收响应。每次查询后,必须刷新输出,然后读取一个整数 —— 即该查询的响应。

比较查询的格式为 “C i j”,交换查询的格式为 “S i j”,其中 $i$ 和 $j$ 是两个元素的下标 ($1 \le i, j \le n$)。允许进行 $i = j$ 的查询。

比较查询的响应:如果 $a[i]$ 与 $a[j]$ “近似相等”,则返回 $0$;否则,如果 $a[i] < a[j]$,返回 $-1$;如果 $a[i] > a[j]$,返回 $1$。

交换查询会交换 $a[i]$ 和 $a[j]$ 的值。如果交换后数组变为升序,则交换查询的响应为 $1$,否则为 $0$。

你的程序应在收到交换查询的响应 $1$ 后立即退出。

程序至少需要进行一次交换查询。例如,如果隐藏的排列已经是有序的,它可以进行一次 “S 1 1” 查询,收到 $1$ 后退出。

样例

输入格式 1

4
-1
-1
1
1

输出格式 1

C 1 2
C 2 3
C 3 4
S 3 4

输入格式 2

1
1

输出格式 2

S 1 1

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.