题目大意:给定一个 N 个点的序列,求有多少个区间满足(oplus_{i=l}^ra[i]=sumlimits_{i=l}^ra[i])。
题解:
小结论:(aoplus b=a+b
ightarrow a&b=0)。
对每个点来说,考虑向右延伸能够满足条件的右端点的位置,显然右端点的位置单调不减,双指针扫一遍即可。
代码如下
#include <cstdio>
using namespace std;
const int maxn=2e5+10;
int n,a[maxn];
long long ans;
void solve(){
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
for(int l=1,r=1,now=0;l<=n;){
while(r<=n&&now+a[r]==(now^a[r]))now^=a[r++];
ans+=r-l,now^=a[l++];
}
printf("%lld
",ans);
}
int main(){
solve();
return 0;
}