1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| class Solution { public: vector<int> xorQueries(vector<int>& arr, vector<vector<int>>& queries) { const int n = arr.size(); vector<int> prefix(n + 1); int i = -1; while (++i < n) { prefix[i + 1] = prefix[i] ^ arr[i]; } vector<int> ans(queries.size()); i = 0; for (auto& q : queries) ans[i++] = prefix[q[1] + 1] ^ prefix[q[0]]; return ans; } };
|