class Solution {
public int[] xorQueries(int[] arr, int[][] queries) {
FenwickTree fenwickTree = new FenwickTree(arr.length);
for (int i = 0; i < arr.length; i++) {
fenwickTree.add(i+1, arr[i]);
}
int[] ans = new int[queries.length];
for (int i = 0; i < queries.length; i++) {
ans[i] = fenwickTree.query(queries[i][0]) ^ fenwickTree.query(queries[i][1]+1);
}
return ans;
}
class FenwickTree{
int[] arr;
public FenwickTree(int n){
arr = new int[n+1];
}
public int lowBit(int i){
return i & ( -i );
}
public void add(int idx, int num){
while (idx < arr.length){
arr[idx] ^= num;
idx += lowBit(idx);
}
}
public int query(int idx){
int res = 0;
while (idx > 0 ){
res ^= arr[idx];
idx -= lowBit(idx);
}
return res;
}
}
}
class Solution {
public int maxSubArray(int[] nums) {
int i = 1;
for (; i < nums.length; i++) {
nums[i] = nums[i] + nums[i-1];
}
int max = nums[0];
int beforMin = 0;
for (i = 0; i < nums.length; i++) {
max = Math.max(max,nums[i]-beforMin);
beforMin = Math.min(nums[i],beforMin);
}
return max;
}
}