PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000135. Tất cả giá trị XOR của đoạn con (All Subarray Xors)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tất cả giá trị XOR của đoạn con (All Subarray Xors)
All Subarray Xors
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
An integer array is given. A subarray consists of all elements from position through position , where . Its value is the bitwise XOR . List every distinct value attained by a nonempty subarray, including zero only if a nonempty subarray has XOR zero.
Input
- Line 1: integer , the array length.
- Line 2: integers in order.
Output
Print the number of distinct attainable XOR values on the first line. On the next line, print the values in strictly increasing order, separated by spaces.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Example 1
Input
4
5 1 5 9
Output
7
1 4 5 8 9 12 13
Explanation
Lengths 1, 2, 3 and 4 give respectively (5, 1, 5, 9), (4, 4, 12), (1, 13) and (8). Removing duplicates and sorting yields the seven printed values.
Example 2
Input
2
7 7
Output
2
0 7
Explanation
Both singletons have XOR 7. The entire array has XOR , so the answer set is .