public int[] XorQueries(int[] arr, int[][] queries) { PrefixXOR p = new PrefixXOR(arr); int[] ans = new int[queries.Length]; int i = 0; foreach (int[] q in queries) { ans[i++] = p.Query(q[0], q[1]); } return(ans); }
public int CountTriplets(int[] arr) { PrefixXOR p = new PrefixXOR(arr); // for a = b, a ^ b = 0. // Therefore, arr[i] ^ arr[i+1] ^...^ arr[k] // Once we settle a legal range of (i,k), we have k - i choice because i < j <= k int n = arr.Length; int count = 0; for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { if (p.Query(i, j) == 0) { count += j - i; } } } return(count); }