CF1017C.The Phone Number

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Mrs. Smith is trying to contact her husband, John Smith, but she forgot the secret phone number!

The only thing Mrs. Smith remembered was that any permutation of nn can be a secret phone number. Only those permutations that minimize secret value might be the phone of her husband.

The sequence of nn integers is called a permutation if it contains all integers from 11 to nn exactly once.

The secret value of a phone number is defined as the sum of the length of the longest increasing subsequence (LIS) and length of the longest decreasing subsequence (LDS).

A subsequence ai1,ai2,…,aika_{i_1}, a_{i_2}, \ldots, a_{i_k} where 1≤i1<i2<…<ik≤n1\leq i_1 \lt i_2 \lt \ldots \lt i_k\leq n is called increasing if ai1<ai2<ai3<…<aika_{i_1} \lt a_{i_2} \lt a_{i_3} \lt \ldots \lt a_{i_k}. If ai1>ai2>ai3>…>aika_{i_1} \gt a_{i_2} \gt a_{i_3} \gt \ldots \gt a_{i_k}, a subsequence is called decreasing. An increasing/decreasing subsequence is called longest if it has maximum length among all increasing/decreasing subsequences.

For example, if there is a permutation [6,4,1,7,2,3,5][6, 4, 1, 7, 2, 3, 5], LIS of this permutation will be [1,2,3,5][1, 2, 3, 5], so the length of LIS is equal to 44. LDS can be [6,4,1][6, 4, 1], [6,4,2][6, 4, 2], or [6,4,3][6, 4, 3], so the length of LDS is 33.

Note, the lengths of LIS and LDS can be different.

So please help Mrs. Smith to find a permutation that gives a minimum sum of lengths of LIS and LDS.

史密斯夫人正试图联系她的丈夫约翰·史密斯,但她忘记了那个秘密电话号码!

她唯一记得的是:任意一个 nn 的排列都可能成为秘密电话号码。而只有那些使“秘密值”最小的排列,才有可能是她丈夫的电话号码。

由 nn 个整数组成的序列被称为一个排列,当且仅当它恰好包含从 11 到 nn 的每一个整数各一次。

一个电话号码的秘密值被定义为:其最长递增子序列(LIS)的长度与最长递减子序列(LDS)的长度之和。

子序列 ai1,ai2,…,aika_{i_1}, a_{i_2}, \ldots, a_{i_k}(其中 1≤i1<i2<…<ik≤n1\leq i_1 \lt i_2 \lt \ldots \lt i_k\leq n)被称为递增的,若满足 ai1<ai2<ai3<…<aika_{i_1} \lt a_{i_2} \lt a_{i_3} \lt \ldots \lt a_{i_k};若满足 ai1>ai2>ai3>…>aika_{i_1} \gt a_{i_2} \gt a_{i_3} \gt \ldots \gt a_{i_k},则称为递减的。在所有递增(或递减)子序列中长度最大的那个,就称为最长递增子序列(LIS)(或最长递减子序列(LDS))。

例如,对排列 [6,4,1,7,2,3,5][6, 4, 1, 7, 2, 3, 5],其 LIS 可为 [1,2,3,5][1, 2, 3, 5],故 LIS 长度为 44;LDS 可为 [6,4,1][6, 4, 1]、[6,4,2][6, 4, 2] 或 [6,4,3][6, 4, 3],故 LDS 长度为 33。

注意:LIS 与 LDS 的长度可以不同。

因此,请帮助史密斯夫人找出一个使 LIS 长度与 LDS 长度之和最小的排列。

输入格式

The only line contains one integer nn (1≤n≤1051 \le n \le 10^5) — the length of permutation that you need to build.

唯一的一行包含一个整数 nn(1≤n≤1051 \le n \le 10^5)——你需要构造的排列的长度。

输出格式

Print a permutation that gives a minimum sum of lengths of LIS and LDS.

If there are multiple answers, print any.

输出一个排列,使得其最长递增子序列(LIS)与最长递减子序列(LDS)的长度之和最小。

若存在多个答案,输出任意一个即可。

输入输出样例

  • 输入#1

    4

    输出#1

    3 4 1 2
  • 输入#2

    2

    输出#2

    2 1

说明/提示

In the first sample, you can build a permutation [3,4,1,2][3, 4, 1, 2]. LIS is [3,4][3, 4] (or [1,2][1, 2]), so the length of LIS is equal to 22. LDS can be ony of [3,1][3, 1], [4,2][4, 2], [3,2][3, 2], or [4,1][4, 1]. The length of LDS is also equal to 22. The sum is equal to 44. Note that [3,4,1,2][3, 4, 1, 2] is not the only permutation that is valid.

In the second sample, you can build a permutation [2,1][2, 1]. LIS is [1][1] (or [2][2]), so the length of LIS is equal to 11. LDS is [2,1][2, 1], so the length of LDS is equal to 22. The sum is equal to 33. Note that permutation [1,2][1, 2] is also valid.

在第一个样例中,你可以构造一个排列 [3,4,1,2][3, 4, 1, 2]。其最长递增子序列(LIS)为 [3,4][3, 4](或 [1,2][1, 2]),因此 LIS 的长度为 22。最长递减子序列(LDS)可以是 [3,1][3, 1]、[4,2][4, 2]、[3,2][3, 2] 或 [4,1][4, 1] 中的任意一个,因此 LDS 的长度也为 22。两者之和为 44。注意,[3,4,1,2][3, 4, 1, 2] 并非唯一合法的排列。

在第二个样例中,你可以构造一个排列 [2,1][2, 1]。其 LIS 为 [1][1](或 [2][2]),因此 LIS 的长度为 11。其 LDS 为 [2,1][2, 1],因此 LDS 的长度为 22。两者之和为 33。注意,排列 [1,2][1, 2] 同样合法。

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

首页