30 Days of Code [Day 17]
QUESTION : 1310. XOR Queries of a Subarray
#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define fo(i,s,n) for(int i=s;i<n;++i)
#define of(i,s,n) for(int i=s-1;i>=n;--i)
#define fv(V) for( auto &it : V )
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
class Solution {
public:
vector<int> xorQueries(vector<int>& arr, vector<vector<int>>& queries) {
fastio;
int n = arr.size();
vi res;
res.reserve(queries.size());
fo(i,1,n){
arr[i] = (arr[i-1] ^ arr[i]);
}
fv(queries){
if(!it[0])
res.pb(arr[it[1]]);
else res.pb(arr[it[0]-1] ^ arr[it[1]]);
}
return res;
}
};