CF909F.AND-permutations

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Given an integer N, find two permutations:

  1. Permutation p of numbers from 1 to N such that p__i ≠ i and p__i & i = 0 for all i = 1, 2, ..., N.
  2. Permutation q of numbers from 1 to N such that q__i ≠ i and q__i & i ≠ 0 for all i = 1, 2, ..., N.

& is the bitwise AND operation.

给定一个整数 NN,请找出两个排列:

  1. 排列 pp,由 11 到 NN 的整数组成,满足对所有 i=1,2,…,Ni = 1, 2, \dots, N,均有 pi≠ip_i \ne i 且 pi&i=0p_i \mathbin{\&} i = 0;
  2. 排列 qq,由 11 到 NN 的整数组成,满足对所有 i=1,2,…,Ni = 1, 2, \dots, N,均有 qi≠iq_i \ne i 且 qi&i≠0q_i \mathbin{\&} i \ne 0。

其中 &\& 表示按位与运算。

输入格式

The input consists of one line containing a single integer N (1 ≤ N ≤ 105).

输入包含一行,其中有一个整数 NN(1≤N≤1051 \leq N \leq 10^5)。

输出格式

For each subtask, if the required permutation doesn't exist, output a single line containing the word "NO"; otherwise output the word "YES" in the first line and N elements of the permutation, separated by spaces, in the second line. If there are several possible permutations in a subtask, output any of them.

对于每个子任务,如果所要求的排列不存在,则输出一行单词“NO”;否则,第一行输出单词“YES”,第二行输出该排列的 N 个元素(以空格分隔)。若某个子任务存在多个可能的排列,输出其中任意一个即可。

输入输出样例

  • 输入#1

    3

    输出#1

    NO
    NO
  • 输入#2

    6

    输出#2

    YES
    6 5 4 3 2 1 
    YES
    3 6 2 5 1 4

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

首页