扫过去 算累积几个pair是同parity
最后看subarray头尾的累积数量是不是一样
就知道这个subarray里面有没有同parity的pair
def isArraySpecial(self, nums: List[int], queries: List[List[int]]) ->
List[bool]:
mem = [0]
pre, cur_cnt = nums[0]%2, 0
for i in range(1, len(nums)):
if nums[i]%2 == pre:
cur_cnt += 1
else:
pre = nums[i]%2
mem.append(cur_cnt)
ans = [mem[q[1]]==mem[q[0]] for q in queries]
return ans