#P8944. The Da Vinci Code

    ID: 9970 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划 DP数学2023洛谷原创O2优化矩阵加速

The Da Vinci Code

Background

The Holy Grail waits quietly beneath Rosslyn Chapel.
It sleeps embraced in the shadow of a masterwork.
Blade and Grail guard the doorway of her home.
Under the starry sky she may rest in peace.

A good problem does not need a fancy background.

Problem Description

Given a sequence aa of length nn, initially ai=ia_i = i.

There is also a random integer xx with value in [1,n][1,n]. The probability that it equals ii is bib_i.

Then perform kk operations. In each operation, uniformly at random choose two integers i,ji, j from [1,n][1,n] (allowing i=ji=j), and swap the values of aia_i and aja_j (if i=ji=j, do nothing). Ask for the probability that finally xx is at position ii. You need to compute the answer for all 1in1 \le i \le n. Output the answers modulo 32212254733221225473.

We say that xx is at position ii if ai=xa_i = x.

Input Format

One line contains three integers n,k,seedn, k, seed. Then generate bib_i using the following code:

#include <cstdio>

typedef unsigned long long ull;
typedef unsigned int uint;
typedef long long ll;

const uint mod = 3221225473u;
const int N = 20000010;

ull seed;

ull getnext() {
	seed ^= seed << 13;
	seed ^= seed >> 17;
	seed ^= seed << 5;
	return seed;
}

uint rd(uint l, uint r) {
	return getnext() % (r - l + 1) + l;
}

int n;
ull k;
uint b[N];

int main() {
	scanf("%d%llu%llu", &n, &k, &seed);
	ull sum = 0;
	for (int i = 1; i < n; ++ i) b[i] = rd(2u, mod - 1), (sum += b[i]) %= mod;
	b[n] = mod + 1 - sum;
}

Output Format

Let ansians_i be the probability that xx is at position ii modulo 32212254733221225473. Output the XOR-sum of ansi×ians_i \times i.

2 9 998244353

2684354563

7 3 123456789

24313281849

10 9000000000000000000 1000000000000000000

20026214895

4 0 123456789

12357556560

Hint

Sample Explanation

For Sample #1:

The array bb is {2134949164,1086276310}\{2134949164, 1086276310\}. After 99 operations, the probabilities that xx is at the two positions are both 12\dfrac12.

For Sample #2:

The array bb is $\{1863763622, 1043615898, 1055155266, 1556793106, 1763540175, 1239801170, 1141007183\}$.

Constraints

For 100%100\% of the testdata:

  • 2n2×1072 \le n \le 2 \times 10^7, 0k,seed<2640 \le k, seed < 2^{64}.
  • 1<bi<32212254731 < b_i < 3221225473, i=1nbi1(mod3221225473)\sum\limits_{i=1}^n b_i \equiv 1 \pmod{3221225473}.
  • The testdata guarantees 1<bn<32212254731 < b_n < 3221225473 and 32212254733221225473 is prime.

This problem uses bundled tests.

Subtask\text{Subtask} nn \le kk \le Score
00 22 26412^{64}-1 11
11 55 44
22 200200 200200 66
33 26412^{64}-1 99
44 20002000 77
55 2×1072 \times 10^7 11 55
66 10610^6 88
77 2×1072 \times 10^7 10710^7 1010
88 10610^6 26412^{64}-1 1515
99 2×1072 \times 10^7 3535

Translated by ChatGPT 5