PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000134. Đếm bộ ba có hai đoạn XOR bằng nhau (Count Triplets That Can Form Two Arrays of Equal XOR)
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 bộ ba có hai đoạn XOR bằng nhau (Count Triplets That Can Form Two Arrays of Equal XOR)
Count Triplets That Can Form Two Arrays of Equal XOR
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
An array of positive integers is indexed from zero. Choose indices . They define two adjacent nonempty intervals and . A triplet qualifies when
$$a_i\oplus\cdots\oplus a_{j-1}=a_j\oplus\cdots\oplus a_k.$$Count qualifying triplets; differing in any index makes two triplets distinct.
Input
First line: integer .
Second line: integers .
Output
Print the number of qualifying triplets.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Example 1
Input
5
2 3 1 6 7
Output
4
Explanation
The triplets have equal-side XORs 2,1,1,7 respectively. Only intervals and have XOR zero; each admits two cuts.
Example 2
Input
5
1 1 1 1 1
Output
10
Explanation
Four intervals of length 2 each have one cut, and two intervals of length 4 each have three cuts. Odd-length intervals have XOR 1 and cannot qualify. Total: .