QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 256 MB Points totaux : 100

#5053. 随机洗牌

Statistiques

Pang 教授正在挑选晋级世界总决赛的队伍。由于地区赛被取消,他使用随机洗牌来对队伍进行排名。总共有 $n$ 支队伍。他的代码如下:

uint64_t x;//uint64_t represents 64-bit unsigned integer
int n;
uint64_t rand() {//this is a xor-shift random generator
x ^= x << 13;
x ^= x >> 7;
x ^= x << 17;
return x;
}
int main() {
cin >> n;
cin >> x;
for (int i = 1; i <= n; i++) {//random shuffle [1, 2,..., n]
a[i] = i;
swap(a[i], a[rand() % i + 1]);
}
for (int i = 1; i <= n; i++) {//print the result
cout << a[i] << (i == n ? '\n' : ' ');
}
}

他编译并运行了他的代码,然后输入了 $n$ 和某个特殊的非负整数 $x$。他将结果打印在了纸上。

一天后,Pang 教授忘记了他选择的 $x$。现在给定代码运行的结果和整数 $n$,请恢复 Pang 教授输入的数字 $x$。

输入格式

第一行包含一个整数 $n$ ($50 \le n \le 100000$),表示队伍数量。 接下来一行包含 $n$ 个整数,即 Pang 教授代码打印的结果。保证结果是正确的,即存在一个整数 $x$ ($0 \le x \le 2^{64} - 1$) 可以得到该结果。

输出格式

输出 Pang 教授输入的整数 $x$ ($0 \le x \le 2^{64} - 1$)。如果有多个可能的 $x$,输出任意一个即可。

样例

输入 1

50
36 22 24 21 27 50 28 14 25 34 18 43 47
13 30 7 10 48 20 16 29 9 8 15 3 31 12
38 19 49 37 1 46 32 4 44 11 35 6 33 26
5 45 17 39 40 2 23 42 41

输出 1

16659580358178468547

说明

注意,样例输入的第二行为了适应页面宽度进行了换行。

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.