QOJ.ac

QOJ

Limite de temps : 2.0 s Limite de mémoire : 1024 MB Points totaux : 100 Hackable ✓

#10321. PQ 和 QP 的逆序对

Statistiques

给定三个整数 $N, A$ 和 $B$。

考虑两个 $(1, 2, \dots, N)$ 的排列 $P = (P_1, P_2, \dots, P_N)$ 和 $Q = (Q_1, Q_2, \dots, Q_N)$,满足以下条件:

  • 序列 $(P_{Q_1}, P_{Q_2}, \dots, P_{Q_N})$ 的逆序对数量等于 $A$。
  • 序列 $(Q_{P_1}, Q_{P_2}, \dots, Q_{P_N})$ 的逆序对数量等于 $B$。

请判断是否存在这样的排列,如果存在,请构造出一组示例。 你需要处理 $T$ 组测试数据。

逆序对的定义

长度为 $M$ 的序列 $R = (R_1, R_2, \dots, R_M)$ 的逆序对数量,是指满足 $1 \le i < j \le M$ 且 $R_i > R_j$ 的整数对 $(i, j)$ 的数量。

输入格式

输入通过标准输入按以下格式给出:

$T$ $case_1$ $\vdots$ $case_T$

每组测试数据按以下格式给出:

$N \ A \ B$

  • $1 \le T \le 2 \times 10^5$
  • $1 \le N \le 2 \times 10^5$
  • $0 \le A \le \frac{N(N - 1)}{2}$
  • $0 \le B \le \frac{N(N - 1)}{2}$
  • 所有测试数据的 $N$ 之和不超过 $2 \times 10^5$。
  • 所有输入值均为整数。

输出格式

按以下格式输出 $case_1, case_2, \dots, case_T$ 的答案。

如果存在满足条件的排列 $P = (P_1, P_2, \dots, P_N)$ 和 $Q = (Q_1, Q_2, \dots, Q_N)$,请按以下格式输出其中任意一组:

Yes $P_1 \ P_2 \ \dots \ P_N$ $Q_1 \ Q_2 \ \dots \ Q_N$

如果不存在这样的排列,输出 No。

样例

输入 1

3
3 3 1
3 1 2
8 13 11

输出 1

Yes
1 3 2
2 3 1
No
Yes
2 5 8 4 6 3 7 1
2 1 8 5 3 7 4 6

说明

对于第一组测试数据的输出示例,$(P_{Q_1}, P_{Q_2}, P_{Q_3}) = (3, 2, 1)$ 且 $(Q_{P_1}, Q_{P_2}, Q_{P_3}) = (2, 1, 3)$。

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.