#P1093. 异或区间

异或区间

题目背景

⊕\oplus 代表异或(xor)运算,运算规则为:

  • 当只有一位比特参与运算时,0⊕0=00\oplus0=0,0⊕1=10\oplus1=1,1⊕0=11\oplus0=1,1⊕1=01\oplus1=0(相同为00,相异为11);
  • 当有多位比特参与运算时,对每位比特分别取异或运算,如 0101⊕1011=11100101\oplus 1011=1110;

题目描述

给定一个长度为 nn的序列a1,a2,…,ana_1,a_2,\dots,a_n,求这个序列有多少个区间 l≤rl\leq r 满足以下条件:

$$a_l + a_{l+1} + \dots +a_{r-1} +a_r =a_l \oplus a_{l+1} \oplus \dots \oplus a_{r-1} \oplus a_r$$

输入格式

  • 第一行:单个整数表示 nn
  • 第二行:nn 个整数表示 a1,a2,…,ana_1,a_2,\dots,a_n

输出格式

  • 单个整数表示答案。
4
1 2 4 2
8

数据范围

  • 30%30\% 的数据,1≤n≤1001\leq n\leq 100
  • 60%60\% 的数据,1≤n≤20001\leq n\leq 2000
  • 100%100\% 的数据,1≤n≤300,0001\leq n\leq 300,000,0≤ai<2300 \leq a_i< 2^{30}