PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000161. Đếm đoạn XOR bằng K (Count Subarrays With XOR K)
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 XOR bằng K (Count Subarrays With XOR K)
Count Subarrays With XOR K
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given an array of integers , numbered from 1. A nonempty contiguous interval contains all elements from through and has length . Count intervals whose bitwise XOR of all elements is equal to . Bitwise XOR has a 1 at a bit position exactly when an odd number of operands have a 1 there. Intervals with different endpoints are counted separately.
Input
The first line contains two integers . The second line contains integers .
Output
Print one integer: the number of qualifying intervals.
Subtasks
- Subtask 1 (20 points): ; for all ; .
- Subtask 2 (30 points): ; for all ; .
- Subtask 3 (50 points): ; for all ; .
Example 1
Input
3 3
1 2 3
Output
2
Explanation
Intervals [1,2] and [3,3] have XOR 3; the others have XOR 1, 0, 2, 1.
Example 2
Input
2 0
0 0
Output
3
Explanation
Both singletons and [1,2] have XOR zero.