CF1582F1.Korney Korneevich and XOR (easy version)

普及+/提高

通过率:0%

时间限制:1.50s

内存限制:512MB

AC君温馨提醒

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

题目描述

This is an easier version of the problem with smaller constraints.

Korney Korneevich dag up an array aa of length nn. Korney Korneevich has recently read about the operation bitwise XOR, so he wished to experiment with it. For this purpose, he decided to find all integers x≥0x \ge 0 such that there exists an increasing subsequence of the array aa, in which the bitwise XOR of numbers is equal to xx.

It didn't take a long time for Korney Korneevich to find all such xx, and he wants to check his result. That's why he asked you to solve this problem!

A sequence ss is a subsequence of a sequence bb if ss can be obtained from bb by deletion of several (possibly, zero or all) elements.

A sequence s1,s2,…,sms_1, s_2, \ldots , s_m is called increasing if s1<s2<…<sms_1 \lt s_2 \lt \ldots \lt s_m.

这是一个约束条件更小的简化版本问题。

科尔尼·科尔涅耶维奇构造了一个长度为 nn 的数组 aa。科爾尼·科尔涅耶维奇最近学习了按位异或(XOR)运算,因此希望对此进行实验。为此,他决定找出所有满足 x≥0x \ge 0 的整数 xx,使得数组 aa 中存在一个严格递增子序列,该子序列中所有元素的按位异或结果恰好等于 xx。

科爾尼·科尔涅耶维奇很快便找出了所有这样的 xx,现在他想验证自己的结果是否正确。因此,他请你来解决这个问题!

若序列 ss 可通过从序列 bb 中删除若干(可能为零个或全部)元素而得到,则称 ss 是 bb 的一个子序列。

序列 s1,s2,…,sms_1, s_2, \ldots , s_m 称为严格递增的,当且仅当 s1<s2<…<sms_1 \lt s_2 \lt \ldots \lt s_m。

输入格式

The first line contains a single integer nn (1≤n≤1051 \le n \le 10^5).

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤5000 \le a_i \le 500) — the elements of the array aa.

第一行包含一个整数 nn(1≤n≤1051 \le n \le 10^5)。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤5000 \le a_i \le 500)——数组 aa 的元素。

输出格式

In the first line print a single integer kk — the number of found xx values.

In the second line print kk integers in increasing order x1,x2,…xkx_1, x_2, \ldots x_k (0≤x1<…<xk0 \le x_1 \lt \ldots \lt x_k) — found xx values.

第一行输出一个整数 kk —— 找到的 xx 值的个数。

第二行按升序输出 kk 个整数 x1,x2,…,xkx_1, x_2, \ldots, x_k(满足 0≤x1<…<xk0 \le x_1 \lt \ldots \lt x_k)—— 找到的 xx 值。

输入输出样例

  • 输入#1

    4
    4 2 2 4

    输出#1

    4
    0 2 4 6
  • 输入#2

    8
    1 0 1 7 12 5 3 2

    输出#2

    12
    0 1 2 3 4 5 6 7 10 11 12 13

说明/提示

In the first test case:

  • To get value x=0x = 0 it is possible to choose and empty subsequence
  • To get value x=2x = 2 it is possible to choose a subsequence [2][2]
  • To get value x=4x = 4 it is possible to choose a subsequence [4][4]
  • To get value x=6x = 6 it is possible to choose a subsequence [2,4][2, 4]

在第一个测试用例中:

  • 要得到值 x=0x = 0,可以选择一个空子序列;
  • 要得到值 x=2x = 2,可以选择子序列 [2][2];
  • 要得到值 x=4x = 4,可以选择子序列 [4][4];
  • 要得到值 x=6x = 6,可以选择子序列 [2,4][2, 4]。

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

首页