leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1310.cpp (402B)


      1 class Solution {
      2   public:
      3     vector<int> xorQueries(const vector<int> &arr, const vector<vector<int>> &q) {
      4         const int n = arr.size(), m = q.size();
      5         vector<int> sum(n + 1), res(m);
      6         for (int i = 0, acc = 0; i < n; i++)
      7             sum[i + 1] = acc ^= arr[i];
      8         for (int i = 0; i < m; i++)
      9             res[i] = sum[q[i][1] + 1] ^ sum[q[i][0]];
     10         return res;
     11     }
     12 };