CF444B.DZY Loves FFT

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

DZY loves Fast Fourier Transformation, and he enjoys using it.

Fast Fourier Transformation is an algorithm used to calculate convolution. Specifically, if a, b and c are sequences with length n, which are indexed from 0 to n - 1, and

We can calculate c fast using Fast Fourier Transformation.

DZY made a little change on this formula. Now

To make things easier, a is a permutation of integers from 1 to n, and b is a sequence only containing 0 and 1. Given a and b, DZY needs your help to calculate c.

Because he is naughty, DZY provides a special way to get a and b. What you need is only three integers n, d, x. After getting them, use the code below to generate a and b.

//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)]);
}
}

Operation x % y denotes remainder after division x by y. Function swap(x, y) swaps two values x and y.

DZY 热爱快速傅里叶变换(Fast Fourier Transformation),并乐于使用它。

快速傅里叶变换是一种用于计算卷积的算法。具体而言,若 aa、bb 和 cc 是长度均为 nn 的序列,下标范围为 00 到 n−1n-1,且满足:

则我们可利用快速傅里叶变换高效地计算出序列 cc。

DZY 对该公式做了一点改动。现在定义为:

为简化问题,aa 是 11 到 nn 这 nn 个整数的一个排列,而 bb 是一个仅由 00 和 11 构成的序列。给定 aa 和 bb,DZY 需要你帮助他计算出 cc。

由于他天性顽皮,DZY 提供了一种特殊的生成 aa 和 bb 的方式。你只需获得三个整数 nn、dd、xx。获取后,使用以下代码生成 aa 和 bb:

// x 是一个 64 位变量;
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)]);
}
}

运算符 x%yx \% y 表示 xx 除以 yy 后所得的余数。函数 swap(x, y) 交换两个值 xx 和 yy。

输入格式

The only line of input contains three space-separated integers n, d, x (1 ≤ d ≤ n ≤ 100000; 0 ≤ x ≤ 1000000006). Because DZY is naughty, x can't be equal to 27777500.

输入仅包含一行,其中为三个以空格分隔的整数 nn、dd、xx(1 ≤ d ≤ n ≤ 1000001 \le d \le n \le 100000;0 ≤ x ≤ 10000000060 \le x \le 1000000006)。由于 DZY 很淘气,xx 不能等于 2777750027777500。

输出格式

Output n lines, the i-th line should contain an integer c__i - 1.

输出 n 行,第 i 行应包含一个整数 c__i - 1。

输入输出样例

  • 输入#1

    3 1 1

    输出#1

    1
    3
    2
  • 输入#2

    5 4 2

    输出#2

    2
    2
    4
    5
    5
  • 输入#3

    5 4 3

    输出#3

    5
    5
    5
    5
    4

说明/提示

In the first sample, a is [1 3 2], b is [1 0 0], so _c_0 = max(1·1) = 1, _c_1 = max(1·0, 3·1) = 3, _c_2 = max(1·0, 3·0, 2·1) = 2.

In the second sample, a is [2 1 4 5 3], b is [1 1 1 0 1].

In the third sample, a is [5 2 1 4 3], b is [1 1 1 1 0].

在第一个样例中,aa 为 [1 3 2][1\ 3\ 2],bb 为 [1 0 0][1\ 0\ 0],因此 c0=max⁡(1⋅1)=1c_0 = \max(1\cdot1) = 1,c1=max⁡(1⋅0, 3⋅1)=3c_1 = \max(1\cdot0,\ 3\cdot1) = 3,c2=max⁡(1⋅0, 3⋅0, 2⋅1)=2c_2 = \max(1\cdot0,\ 3\cdot0,\ 2\cdot1) = 2。

在第二个样例中,aa 为 [2 1 4 5 3][2\ 1\ 4\ 5\ 3],bb 为 [1 1 1 0 1][1\ 1\ 1\ 0\ 1]。

在第三个样例中,aa 为 [5 2 1 4 3][5\ 2\ 1\ 4\ 3],bb 为 [1 1 1 1 0][1\ 1\ 1\ 1\ 0]。

输入解题思路,AI测评打分。不知道怎么写?

首页