CF1205F.Beauty of a Permutation

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Define the beauty of a permutation of numbers from 11 to nn (p1,p2,…,pn)(p_1, p_2, \dots, p_n) as number of pairs (L,R)(L, R) such that 1≤L≤R≤n1 \le L \le R \le n and numbers pL,pL+1,…,pRp_L, p_{L+1}, \dots, p_R are consecutive R−L+1R-L+1 numbers in some order. For example, the beauty of the permutation (1,2,5,3,4)(1, 2, 5, 3, 4) equals 99, and segments, corresponding to pairs, are [1][1], [2][2], [5][5], [4][4], [3][3], [1,2][1, 2], [3,4][3, 4], [5,3,4][5, 3, 4], [1,2,5,3,4][1, 2, 5, 3, 4].

Answer qq independent queries. In each query, you will be given integers nn and kk. Determine if there exists a permutation of numbers from 11 to nn with beauty equal to kk, and if there exists, output one of them.

定义 11 到 nn 的一个排列 (p1,p2,…,pn)(p_1, p_2, \dots, p_n) 的**优美值(beauty)**为满足 1≤L≤R≤n1 \le L \le R \le n 且子段 pL,pL+1,…,pRp_L, p_{L+1}, \dots, p_R 恰好是某一种顺序下的连续 R−L+1R-L+1 个整数的区间对 (L,R)(L, R) 的个数。例如,排列 (1,2,5,3,4)(1, 2, 5, 3, 4) 的优美值为 99,对应的所有区间为:[1][1]、[2][2]、[5][5]、[4][4]、[3][3]、[1,2][1, 2]、[3,4][3, 4]、[5,3,4][5, 3, 4]、[1,2,5,3,4][1, 2, 5, 3, 4]。

回答 qq 个相互独立的查询。在每个查询中,你将被给定整数 nn 和 kk。请判断是否存在一个 11 到 nn 的排列,其优美值恰好为 kk;若存在,请输出其中任意一个。

输入格式

The first line contains a single integer qq (1≤q≤10 0001\le q \le 10\,000) — the number of queries.

Follow qq lines. Each line contains two integers nn, kk (1≤n≤1001 \le n \le 100, 1≤k≤n(n+1)21 \le k \le \frac{n(n+1)}{2}) — the length of permutation and needed beauty respectively.

第一行包含一个整数 qq(1≤q≤10 0001\le q \le 10\,000)—— 查询次数。

接下来是 qq 行,每行包含两个整数 nn 和 kk(1≤n≤1001 \le n \le 100,1≤k≤n(n+1)21 \le k \le \frac{n(n+1)}{2})—— 分别表示排列的长度和所需的“优美度”。

输出格式

For a query output "NO", if such a permutation doesn't exist. Otherwise, output "YES", and in the next line output nn numbers — elements of permutation in the right order.

如果不存在满足条件的排列,则对于该查询输出“NO”。否则,输出“YES”,并在下一行输出 nn 个数——按正确顺序排列的排列元素。

输入输出样例

  • 输入#1

    4
    1 1
    5 6
    5 8
    5 10

    输出#1

    YES
    1 
    YES
    2 4 1 5 3 
    NO
    YES
    2 3 1 4 5
  • 输入#2

    2
    4 10
    100 1

    输出#2

    YES
    1 2 3 4 
    NO

说明/提示

Let's look at the first example.

The first query: in (1)(1) there is only one segment consisting of consecutive numbers — the entire permutation.

The second query: in (2,4,1,5,3)(2, 4, 1, 5, 3) there are 66 such segments: [2][2], [4][4], [1][1], [5][5], [3][3], [2,4,1,5,3][2, 4, 1, 5, 3].

There is no such permutation for the second query.

The fourth query: in (2,3,1,4,5)(2, 3, 1, 4, 5) there are 1010 such segments: [2][2], [3][3], [1][1], [4][4], [5][5], [2,3][2, 3], [2,3,1][2, 3, 1], [2,3,1,4][2, 3, 1, 4], [4,5][4, 5], [2,3,1,4,5][2, 3, 1, 4, 5].

我们来看第一个例子。

第一个查询:在 (1)(1) 中,仅存在一个由连续数字组成的区间——即整个排列本身。

第二个查询:在 (2,4,1,5,3)(2, 4, 1, 5, 3) 中,共有 66 个这样的区间:[2][2]、[4][4]、[1][1]、[5][5]、[3][3]、[2,4,1,5,3][2, 4, 1, 5, 3]。

第二个查询不存在满足条件的排列。

第四个查询:在 (2,3,1,4,5)(2, 3, 1, 4, 5) 中,共有 1010 个这样的区间:[2][2]、[3][3]、[1][1]、[4][4]、[5][5]、[2,3][2, 3]、[2,3,1][2, 3, 1]、[2,3,1,4][2, 3, 1, 4]、[4,5][4, 5]、[2,3,1,4,5][2, 3, 1, 4, 5]。

输入解题思路,AI测评打分。不知道怎么写?

首页