Hongjun likes FFT
Time limit2sMemory limit512 MB
Generate permutations a and b with the given pseudocode, then compute c[i] = max over valid j of a[j]*b[i-j].
- Level
Easy3 of 10
- Topics
- Array, Simulation, Implementation
- Solved
- No attempts yet
Problem
Hongjun likes the fast Fourier transform (FFT) and uses it often.
FFT is an algorithm for computing a convolution. Given sequences and of length , indexed from element 0 to element , FFT quickly produces the sequence defined below.
Hongjun replaced the sum in this formula with a maximum.
To keep the computation easy, Hongjun only considers the case where holds each number from to exactly once and every element of is 0 or 1. If every product is 0, then is 0. Write a program that computes the sequence once and are fixed.
Hongjun is lazy, so he does not want to list the elements of and one by one. He gives only three integers , , and wants you to build both sequences yourself with the pseudocode below. % is the remainder operator and swap() exchanges two values. Following the pseudocode, contains exactly ones.
//x is 64-bit variable;
function getNextX() {
x = (x * 37 + 10007) % 1000000007;
return x;
}
function initAB() {
for(i = 0; i < n; i = i + 1){
a[i] = i + 1;
}
for(i = 0; i < n; i = i + 1){
swap(a[i], a[getNextX() % (i + 1)]);
}
for(i = 0; i < n; i = i + 1){
if (i < d)
b[i] = 1;
else
b[i] = 0;
}
for(i = 0; i < n; i = i + 1){
swap(b[i], b[getNextX() % (i + 1)]);
}
}
Input
The first line contains three integers , , separated by spaces. (, )
Output
Print the elements of the sequence , from element 0 to element , on one line separated by spaces.