PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000152. Đếm đoạn có tổng bằng XOR (Xor Sum 2)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đếm đoạn có tổng bằng XOR (Xor Sum 2)
Xor Sum 2
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Given nonnegative integers , count the nonempty intervals () satisfying . Here is bitwise XOR: a result bit is set precisely when an odd number of operands have that bit set. For instance, .
Input
- Line 1: integer , the number of elements.
- Line 2: integers in order.
Output
Print the number of qualifying intervals as one integer.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Example 1
Input
4
2 5 4 6
Output
5
Explanation
All four singletons qualify. For [1,2], the sum and XOR both equal 7. Every other interval has a repeated set bit, so its sum differs from its XOR.
Example 2
Input
9
0 0 0 0 0 0 0 0 0
Output
45
Explanation
Every interval has sum and XOR zero. There are intervals.
Example 3
Input
19
885 8 1 128 83 32 256 206 639 16 4 128 689 32 8 64 885 969 1
Output
37
Explanation
The counts of qualifying intervals ending at positions 1 through 19 are 1, 2, 2, 3, 2, 3, 4, 3, 1, 1, 2, 3, 1, 1, 2, 3, 1, 1, 1. They sum to 37.