cswork / OA打开练习工作台

CitadelOA #15

Get Distinct Goodness Values

估计中等可在线判题

考点(AI 标注)子序列位运算

Choose a subsequence of the original array that preserves order and is strictly increasing in value, and compute its bitwise OR; return all distinct results in ascending order. The OR of the empty subsequence is 0. The old curated page for problem 1 mistakenly said it returns a count, and this is now restored according to the original text.

输入格式

The first line contains n, followed by n integers. 1≤n≤10000, 1≤a[i]<1024. The separate Fastprep page for problem 15, the same problem, together with the OCR supplies its missing ranges.

输出格式

The first line contains the number of results, and the second line contains the distinct OR values in ascending order, including 0.

样例 1

输入:

4
4 2 4 1

输出:

5
0 1 2 4 6

样例 2

输入:

4
3 2 4 6

输出:

6
0 2 3 4 6 7

样例 3

输入:

4
3 5 5 1

输出:

5
0 1 3 5 7

样例说明

The outputs of the three public examples are, in order: 5 / 0 1 2 4 6; 6 / 0 2 3 4 6 7; 5 / 0 1 3 5 7. These answers were verified by independent enumeration or direct simulation.