CF2218C.The 67th Permutation Problem

入门

通过率:0%

AC君温馨提醒

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

题目描述

Upon arriving at school, Macaque was rather brusquely greeted by his friend, AG-88301, the latter having skived off his homework due to spending the entire night yapping to an unsuspecting stranger about his groundbreaking work on a proof of the Collatz conjecture and his $ 67 $ -th unreciprocated love interest. So, as had become customary, AG-88301, with ever decreasing levels of gratitude or appreciation, made Macaque do his homework for him. At this point, Macaque had had enough, and turned to his minions (you guys!) to solve AG-88301's homework task.

You are given an integer $ n $ . You must construct a permutation $ ^{\text{∗}} $ of length $ 3n $ such that, if you partition the permutation into $ n $ contiguous blocks with $ 3 $ elements, the sum of the medians $ ^{\text{†}} $ of these blocks is maximised.

More formally, you must construct a permutation $ p $ of length $ 3n $ such that $ \sum_{i=0}^{n-1}\operatorname{median}(a_{3i+1},a_{3i+2},a_{3i+3}) $ is maximised. If there are multiple possible $ p $ , output any.

$ ^{\text{∗}} $ A permutation of length $ n $ is an array consisting of $ n $ distinct integers from $ 1 $ to $ n $ in arbitrary order. For example, $ [2,3,1,5,4] $ is a permutation, but $ [1,2,2] $ is not a permutation ( $ 2 $ appears twice in the array), and $ [1,3,4] $ is also not a permutation ( $ n=3 $ but there is $ 4 $ in the array).

$ ^{\text{†}} $ The median of an array $ b $ containing $ 3 $ elements is the $ 2 $ -nd element after $ b $ is sorted in non-decreasing order.

输入格式

Each test contains multiple test cases. The first line contains the number of test cases $ t $ ( $ 1 \le t \le 10^4 $ ). The description of the test cases follows.

The first and only line of each test case contains an integer $ n $ ( $ 1 \leq n \leq 10^5 $ ).

It is guaranteed that the sum of $ 3n $ does not exceed $ 3 \cdot 10^5 $ over all test cases.

输出格式

For each test case, output a permutation $ p $ such that the sum of the medians of the contiguous blocks is maximised. If there are multiple possible $ p $ , output any.

输入输出样例

  • 输入#1

    3
    2
    1
    3

    输出#1

    1 3 4 2 5 6 
    3 1 2
    5 2 4 8 3 9 7 1 6

说明/提示

In the first test case, $ [1,3,4,2,5,6] $ is a possible answer because $ \operatorname{median}(1,3,4) + \operatorname{median}(2,5,6) = 3+5 = 8 $ , and it can be shown that $ 8 $ is the maximal possible sum of medians.

In the second test case, $ [3,1,2] $ is a possible answer because the only achievable sum of medians when $ n=1 $ is $ 2 $ .

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

首页