QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 1024 MB مجموع النقاط: 100 قابلة للهجوم ✓

#18689. Xor 是加法

الإحصائيات

您被給予一個整數 $n$。請找出一個(以 $0$ 為索引)0 到 $n-1$ 的排列 $p$,使得對於每個整數 $i\in[0,n)$,滿足 $p_i\oplus i=p_i+i$。

這裡 $\oplus$ 表示按位互斥或(XOR)運算。互斥或(XOR)是布林代數中的一種邏輯運算,僅在輸入不同(一個為真,另一個為假)時輸出真。換句話說,若且唯若兩個輸入值不相同時,XOR 才會回傳真值。以下是 XOR 的真值表。

| $a$ | $b$ | $a\oplus b$ | |---|---|---| | $0$ | $0$ | $0$ | | $0$ | $1$ | $1$ | | $1$ | $0$ | $1$ | | $1$ | $1$ | $0$ |

按位互斥或是一種二元運算,它取兩個長度相等的位元模式,並對每一對對應位元執行邏輯互斥或運算。例如:$0101$(十進位 $5$)$\oplus$ $0011$(十進位 $3$)$= 0110$(十進位 $6$)。

輸入格式

第一行包含一個整數 $n$ $(1\leq n\leq 10^6)$,表示排列的長度。

輸出格式

在一行中輸出 $n$ 個整數,表示 $p_0, p_1,\dots,p_{n-1}$。如果不存在這樣的排列,則輸出 $-1$。

範例

範例輸入 1

3

範例輸出 1

0 2 1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.