#P8944. The Da Vinci Code
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 of length , initially .
There is also a random integer with value in . The probability that it equals is .
Then perform operations. In each operation, uniformly at random choose two integers from (allowing ), and swap the values of and (if , do nothing). Ask for the probability that finally is at position . You need to compute the answer for all . Output the answers modulo .
We say that is at position if .
Input Format
One line contains three integers . Then generate 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 be the probability that is at position modulo . Output the XOR-sum of .
2 9 998244353
2684354563
7 3 123456789
24313281849
10 9000000000000000000 1000000000000000000
20026214895
4 0 123456789
12357556560
Hint
Sample Explanation
For Sample #1:
The array is . After operations, the probabilities that is at the two positions are both .
For Sample #2:
The array is $\{1863763622, 1043615898, 1055155266, 1556793106, 1763540175, 1239801170, 1141007183\}$.
Constraints
For of the testdata:
- , .
- , .
- The testdata guarantees and is prime.
This problem uses bundled tests.
| Score | |||
|---|---|---|---|
Translated by ChatGPT 5