#P3784. [SDOI2017] 遗忘的集合

    ID: 2726 远端评测题 5000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2017各省省选山东O2优化莫比乌斯反演生成函数快速傅里叶变换 FFT快速数论变换 NTT

[SDOI2017] 遗忘的集合

Description

Little Q posted a bounty on his personal homepage: collect a non-empty set SS containing only positive integers, each not exceeding nn, and satisfying some additional conditions.

As is well known, for any positive integer xx not exceeding nn, we can easily compute the number of ways f(x)f(x) to express xx as a sum of elements from SS. Here, in any representation, each number may be used multiple times, and the order of numbers is ignored.

For example, when S={1,2,3,4,5}S=\{1,2,3,4,5\}, we can compute f(2)=2,f(3)=3,f(4)=5,f(5)=7f(2) = 2, f(3) = 3, f(4) = 5, f(5) = 7.

Another example: when S={1,2,5}S=\{1,2,5\}, we can compute f(4)=3,f(5)=4,f(6)=5,f(7)=6f(4) = 3, f(5) = 4, f(6) = 5, f(7) = 6.

The trouble is that Little Q has forgotten which elements are in SS. Fortunately, he recorded all the values of f(i)modpf(i) \bmod p on a storage device, and he hopes you can use this information to reconstruct the original SS.

Specifically, he wants you to find a non-empty set SS of positive integers, each at most nn, such that for every i=1,2,,ni = 1, 2, \cdots , n, the number of ways to represent ii as a sum of elements from SS is congruent to f(i)f(i) modulo pp, where pp is a prime stored on the device. He guarantees that such an SS exists.

However, Little Q believes the stored information is not enough to recover a unique SS; that is, there may be multiple such sets SS. So he wants the lexicographically smallest one among all solutions.

For two different sets S1S_1 and S2S_2 that satisfy the conditions, we say S1S_1 is lexicographically smaller than S2S_2 if and only if there exists a non-negative integer kk such that the first kk smallest elements of S1S_1 are exactly the same as those of S2S_2, and either S1S_1 has exactly kk elements and S2S_2 has at least (k+1)(k + 1) elements, or both S1S_1 and S2S_2 have at least (k+1)(k + 1) elements and the (k+1)(k + 1)-th smallest element of S1S_1 is smaller than that of S2S_2.

Input Format

The first line contains two integers nn and pp, where pp is prime.

The second line contains nn integers f(1),f(2),,f(n)f(1), f(2), \cdots , f(n), as defined in the statement.

It is guaranteed that in each line adjacent integers are separated by exactly one space, and there is no trailing space at the end of any line.

Output Format

Output two lines describing the lexicographically smallest solution. The first line contains an integer m (m>0)m\ (m > 0), the number of elements in SS. The second line contains mm positive integers s1,s2,,sms_1, s_2, \cdots , s_m, which are the elements of SS sorted in ascending order.

You must ensure that in each output line, adjacent integers are separated by exactly one space, and there is no trailing space at the end of any line.

5 1000003
1 2 3 5 7
5
1 2 3 4 5
9 1000003
1 2 2 3 4 5 6 7 8
3
1 2 5

Hint

For 100%100\% of the testdata, we have 1n<2181 \le n < 2^{18}, 106p<23010^6 \le p < 2^{30}, 0f(i)<p (i=1,2,,n)0 \le f(i) < p \ (i = 1, 2, \cdots , n).

Translated by ChatGPT 5