Skip to content

Commit 9ca4a70

Browse files
committed
leetcode: add 1310
1 parent 94c6b18 commit 9ca4a70

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
typedef long long ll ;
6+
const ll INF=1e18;
7+
const ll mod1=1e9+7;
8+
const ll mod2=998244353;
9+
//Add main code here
10+
11+
class Solution
12+
{
13+
public:
14+
vector<int> xorQueries(vector<int> &arr, vector<vector<int>> &queries)
15+
{
16+
vector<int> ans(queries.size());
17+
int n=arr.size();
18+
vector<int> pref_xor(n,arr[0]);
19+
20+
for(int i=1;i<n;i++){
21+
pref_xor[i]=pref_xor[i-1]^arr[i];
22+
}
23+
for(int i=0;i<queries.size();i++){
24+
int a=queries[i][0], b=queries[i][1];
25+
if(a==0){
26+
ans[i]=pref_xor[b];
27+
}
28+
else{
29+
ans[i]=pref_xor[b]^pref_xor[a-1];
30+
}
31+
}
32+
return ans;
33+
}
34+
};

0 commit comments

Comments
 (0)