CF2145D.Inversion Value of a Permutation
普及+/提高
通过率:0%
时间限制:3.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A permutation of length n is an array of n integers, where each number from 1 to n appears exactly once. An inversion in a permutation p is a pair of indices (i,j) such that i<j and pi>pj.
For a permutation p, we define its inversion value as the number of its subsegments that contain at least one inversion. Formally, this is the number of pairs of integers (l,r) (1≤l<r≤n) for which there exists a pair of indices (i,j) satisfying the following conditions: l≤i<j≤r and pi>pj.
For example, for the permutation [3,1,4,2], the inversion value is 5.
You are given two integers n and k. Your task is to construct a permutation of length n with an inversion value equal to exactly k.
长度为 n 的排列是指由 n 个整数组成的数组,其中每个从 1 到 n 的整数恰好出现一次。排列 p 中的一个逆序对是指满足 i<j 且 pi>pj 的下标对 (i,j)。
对于一个排列 p,我们定义其逆序值为:包含至少一个逆序对的子区间的个数。形式化地说,即满足如下条件的整数对 (l,r)(其中 1≤l<r≤n)的个数:存在一对下标 (i,j),使得 l≤i<j≤r 且 pi>pj。
例如,对于排列 [3,1,4,2],其逆序值为 5。
给定两个整数 n 和 k,你的任务是构造一个长度为 n 的排列,使其逆序值恰好等于 k。
输入格式
The first line contains one integer t (1≤t≤500) — the number of test cases.
Each test case consists of a single line containing two integers n and k (2≤n≤30; 0≤k≤2n(n−1)).
第一行包含一个整数 t(1≤t≤500)—— 测试用例的数量。
每个测试用例由一行组成,包含两个整数 n 和 k(2≤n≤30;0≤k≤2n(n−1))。
输出格式
For each test case, output the answer as follows:
- if the desired permutation does not exist, output a single integer 0;
- otherwise, output n distinct integers from 1 to n — the desired permutation. If there are multiple such permutations, you may output any of them.
对于每个测试用例,按如下方式输出答案:
- 如果所要求的排列不存在,则输出单个整数 0;
- 否则,输出 n 个互不相同的、取值范围在 1 到 n 之间的整数——即所要求的排列。如果存在多个满足条件的排列,输出其中任意一个即可。
输入输出样例
输入#1
5 4 5 5 10 5 0 6 8 3 1
输出#1
3 1 4 2 5 4 3 2 1 1 2 3 4 5 2 3 5 6 1 4 0
输入解题思路,AI测评打分。不知道怎么写?