[力扣] 算法 1310 (C++)

1310. 子数组异或查询

class Solution {
public:
    vector<int> xorQueries(vector<int>&amp; arr, vector<vector<int>>&amp; queries) {
        for (size_t i = 1, size = arr.size(); i < size; ++i) {
            arr[i] ^= arr[i - 1];
        }
        vector<int> ret(queries.size());
        for (size_t i = 0, size = queries.size(); i < size; ++i) {
            int from = queries[i][0], to = queries[i][1];
            ret[i] = arr[to] ^ (from ? arr[from - 1] : 0);
        }
        return ret;
    }
};