Problem Statement

There is an integer sequence A of length N.

Find the number of the pairs of integers l and r (1≤lrN) that satisfy the following condition:

  • Al xor Al+1 xor … xor Ar=Al + Al+1 + … + Ar

Here, xor denotes the bitwise exclusive OR.

Definition of XOR

Constraints

  • 1≤N≤2×105
  • 0≤Ai<220
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A1 A2 AN

Output

Print the number of the pairs of integers l and r (1≤lrN) that satisfy the condition.

Sample Input 1

4
2 5 4 6

Sample Output 1

5

(l,r)=(1,1),(2,2),(3,3),(4,4) clearly satisfy the condition. (l,r)=(1,2) also satisfies the condition, since A1 xor A2=A1 + A2=7. There are no other pairs that satisfy the condition, so the answer is 5.

Sample Input 2

9
0 0 0 0 0 0 0 0 0

Sample Output 2

45

Sample Input 3

19
885 8 1 128 83 32 256 206 639 16 4 128 689 32 8 64 885 969 1

Sample Output 3

37

    发现 xor 0是没有影响的,所以可以把0忽视掉(用一个链表一样的东西)。
因为一旦有两个数 a[i] & a[j] != 0,那么就是不满足的,所以不算0的话长度一定不超过20,所以直接暴力做就行了。
#include<cstring>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<ctime>
#define ll long long
using namespace std;
const int maxn=200005; int n,a[maxn],lef[maxn];
ll ans=0; int main(){
scanf("%d",&n);
for(int i=1,las=0;i<=n;i++){
scanf("%d",a+i),lef[i]=las;
if(a[i]) las=i;
} for(int i=1,now,j;i<=n;i++){
now=a[i]; for(j=lef[i];j;now^=a[j],j=lef[j]) if(now&a[j]) break; ans+=(ll)(i-j); } cout<<ans<<endl;
return 0;
}

  

 

ARC 098 D - Xor Sum 2的更多相关文章

  1. AtCoder Beginner Contest 098 D - Xor Sum 2

    D - Xor Sum 2 Time limit : 2sec / Memory limit : 1024MB Score : 500 points Problem Statement There i ...

  2. AtCoder Regular Contest 098 D - Xor Sum 2 区间异或=相加 DP思想

    题意:给出n个数,求它的连续子序列中,满足下列公式,(l,r)的对数有多少对 Al xor Al+1 xor … xor Ar=Al + Al+1 + … + Ar 思路:由题意可以得到,连续子序列, ...

  3. HDU 4825 Xor Sum(经典01字典树+贪心)

    Xor Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others) Total ...

  4. 字典树-百度之星-Xor Sum

    Xor Sum Problem Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包括了N个正整数,随后 Prometheu ...

  5. HDU 4825 Xor Sum 字典树+位运算

    点击打开链接 Xor Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others) ...

  6. 2014百度之星第三题Xor Sum(字典树+异或运算)

    Xor Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others) Total ...

  7. Xor Sum 01字典树 hdu4825

    Xor Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others)Total S ...

  8. hdu 4825 Xor Sum (01 Trie)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4825 题面: Xor Sum Time Limit: 2000/1000 MS (Java/Others) ...

  9. HDU--4825 Xor Sum (字典树)

    题目链接:HDU--4825 Xor Sum mmp sb字典树因为数组开的不够大一直wa 不是报的 re!!! 找了一下午bug 草 把每个数转化成二进制存字典树里面 然后尽量取与x这个位置上不相同 ...

随机推荐

  1. java中利用正则表达式获取a标签

    // 设置新闻内容 notice.setContent(editorValue); Matcher m = Pattern.compile("<a[^>]*>([^< ...

  2. python 常见的错误类型 和 继承关系

    BaseException +-- SystemExit #系统结束 +-- KeyboardInterrupt #键盘中断 ctrl+D +-- GeneratorExit #主动结束 +-- Ex ...

  3. springmvc maven搭建二之springmvc的security

    上一篇文档初步搭建了一个springmvc的web工程,现在要来实现第二步咯.将登录校验整合到项目中,我用的是spring 3.0.2的版本,所以这里的登录用了security来处理.不多说,上代码. ...

  4. Axios & fetch api & Promise & POST

    Axios & fetch api & Promise & POST https://github.com/axios/axios https://appdividend.co ...

  5. 设计模式之策略模式的Python实现

    1. 策略模式解决的是什么问题 策略模式解决的应用场景是这样的: 在业务场景中,需要用到多个算法,并且每个算法的参数是需要调整的.那么当不同的行为堆砌到同一个类中时,我们很难避免使用条件语句来选择合适 ...

  6. 【ZOJ4063】Tournament(构造)

    题意:n个人要打m轮比赛 每一轮每个人都要有一个对手.而且每个对手只能打一次.假设a与b打了,c与d打了, 那么后面的任意一轮如果a与c打了,那么b就必须和d打 问是否存在方案,输出字典序最小的一组, ...

  7. 我们曾经心碎的数据库之 用SQL语句操作数据

    第八章   用SQL语句操作数据 1.SQL简介 SQL语言是能够识别指令,执行相应的操作并为程序提供数据的一套指令集 SQL的全称: 结构化查询语言(Structured Query Languag ...

  8. php命名空间与可变函数

    命名空间一个最明确的目的就是解决重名问题,PHP中不允许两个函数或者类出现相同的名字,否则会产生一个致命的错误.这种情况下只要避免命名重复就可以解决 对于命名空间,官方文档已经说得很详细[查看],我在 ...

  9. 【leetcode】500. Keyboard Row

    问题描述: Given a List of words, return the words that can be typed using letters of alphabet on only on ...

  10. ubuntu软件包管理

    ubuntu安装好了后首先要会下载和管理系统的软件包:ubuntu的软件管理方式是apt-get 安装软件包apt-get harvey@ubuntu:/var/cache/apt$ which ap ...