XOR THE ARRAY
Practice
4.2 (9 votes)
Math
C++
Basic math
Problem
92% Success 1751 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given an array \(A\) of even length \(N\) consisting of non-negative integers. You need to make each element of the array equal to zero, by doing some number of moves (possibly zero).
In a single move, you can choose two integers, \(l\) and \(r\), so \(1 \leq l \leq r \leq N\). Let \(x = A[l] ⊕ A[l+1] ⊕ A[l+2] ... A[r]\), where ⊕ represents xor operator. Then, replace the whole subarray with \(x\). In other words, assign \(A[i] = x\) for \(l ≤ i ≤ r\).
Print the minimum number of moves required to make the entire array zero.
Input format
- The first line contains a single integer \(N\) – the length of array \(A\).
- The next line contains \(N\) space-separated integers representing the elements of the array \(A\).
Output format
Output a single integer – the answer.
Constraints
\(1 \leq N \leq 10^6\\ \\0\leq A[i] \le 10^9\\ \\N\;is\;even\)
Submissions
Please login to view your submissions
Similar Problems
Points:30
6 votes
Tags:
MathematicsEasy-MediumMathematicsMathamatics
Points:30
78 votes
Tags:
Ad-HocMathematicsOpenApprovedEasy-MediumMathamatics
Points:30
13 votes
Tags:
Basic MathEasy-MediumMathematicsMathematics
Editorial