Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful.

Therefore, Sasha decided to upsolve the following problem:

You have an array aa with n integers. You need to count the number of funny pairs (l,r) (l≤r). To check if a pair (l,r)is a funny pair, take mid=(l+r−1)/2, then if r−l+1 is an even number and al⊕al+1⊕…⊕amid=amid+1⊕amid+2⊕…⊕aral⊕al+1⊕…⊕amid=amid+1⊕amid+2⊕…⊕ar, then the pair is funny. In other words, ⊕ of elements of the left half of the subarray from ll to rr should be equal to ⊕⊕ of elements of the right half. Note that ⊕ denotes the bitwise XOR operation.

It is time to continue solving the contest, so Sasha asked you to solve this task.

Input

The first line contains one integer nn (2≤n≤3⋅10^5) — the size of the array.

The second line contains nn integers a1,a2,…,an (0≤ai<2^20) — array itself.

Output

Print one integer — the number of funny pairs. You should consider only pairs where r−l+1r−l+1 is even number.

Examples

input

Copy

5
1 2 3 4 5

output

Copy

1

input

Copy

6
3 2 2 3 7 6

output

Copy

3

input

Copy

3
42 4 2

output

Copy

0

Note

Be as cool as Sasha, upsolve problems!

In the first example, the only funny pair is (2,5)(2,5), as 2⊕3=4⊕5=12⊕3=4⊕5=1.

In the second example, funny pairs are (2,3)(2,3), (1,4)(1,4), and (3,6)(3,6).

In the third example, there are no funny pairs.

题意:求有多少个异或和相等的偶数区间

思路:先求出前缀异或和,再用二维数组来进行加的运算,因为后面的可以表示奇数和偶数的而来的,之前的会被总结到,要注意单独一个相邻区间的情况,所以我们把b[0][0]=1

代码:

#include<cstdio>
#include<cstring>
#include<queue>
#include<iostream>
#include<algorithm>
#include<stack>
#include<set>
#include<vector>
#include<cmath>
#define MAX 3000005 typedef long long ll; using namespace std;
int b[MAX][2];
int a[MAX];
ll sum=0;
int main()
{
int n;
cin>>n;
b[0][0]=1;
for(int t=1;t<=n;t++)
{
scanf("%d",&a[t]);
a[t]^=a[t-1];
}
for(int t=1;t<=n;t++)
{
sum+=b[a[t]][t&1];
b[a[t]][t&1]++;
}
cout<<sum<<endl;
return 0;
}

Sasha and a Bit of Relax(前缀异或和+二维数组+思维)的更多相关文章

  1. Codeforces Round #539 (Div. 2) C. Sasha and a Bit of Relax(前缀异或和)

    转载自:https://blog.csdn.net/Charles_Zaqdt/article/details/87522917 题目链接:https://codeforces.com/contest ...

  2. 洛谷 P2701 [USACO5.3]巨大的牛棚Big Barn Label:二维数组前缀和 你够了 这次我用DP

    题目背景 (USACO 5.3.4) 题目描述 农夫约翰想要在他的正方形农场上建造一座正方形大牛棚.他讨厌在他的农场中砍树,想找一个能够让他在空旷无树的地方修建牛棚的地方.我们假定,他的农场划分成 N ...

  3. P5057 [CQOI2006]简单题 前缀异或差分/树状数组

    好思路,好思路... 思路:前缀异或差分 提交:1次 题解:区间修改,单点查询,树状数组,如思路$qwq$ #include<cstdio> #include<iostream> ...

  4. AcWing 前缀和 一维加二维

    一维 #include<bits/stdc++.h> using namespace std; ; int n,m; int a[N],s[N]; int main(){ ios::syn ...

  5. 洛谷 P2733 家的范围 Home on the Range Label:二维数组前缀和

    题目背景 农民约翰在一片边长是N (2 <= N <= 250)英里的正方形牧场上放牧他的奶牛.(因为一些原因,他的奶牛只在正方形的牧场上吃草.)遗憾的是,他的奶牛已经毁坏一些土地.( 一 ...

  6. P2280 [HNOI2003]激光炸弹(二维前缀和)

    题目描述 一种新型的激光炸弹,可以摧毁一个边长为R的正方形内的所有的目标.现在地图上有n(n≤10000)个目标,用整数xi,yi(0≤xi,yi≤5000)表示目标在地图上的位置,每个目标都有一个价 ...

  7. HDU - 6336 Problem E. Matrix from Arrays (规律+二维前缀和)

    题意: for (int i = 0; ; ++i) { for (int j = 0; j <= i; ++j) { M[j][i - j] = A[cursor]; cursor = (cu ...

  8. hdu6514 一维化 + 二维前缀和

    http://acm.hdu.edu.cn/showproblem.php?pid=6514 题意 给出一个大矩形(\(nm\leq10^7\)),有p个矩形覆盖,然后有q次询问,询问指定矩形内是否覆 ...

  9. 前缀和&二维前缀和

    我们知道,数组上的前缀和S[i]=S[i-1]+a[i] 那么,怎样求二维前缀和呢? 二维前缀和: 绿色点的前缀和就是黄色.红色.灰色和绿色的点权和 怎样计算? s[i][j]=s[i-1][j]+s ...

随机推荐

  1. 自定义的parse_url逆向函数http_build_url,将数组转为url字符串

    parse_url函数可以讲一个url字符串解析成一个数组,但是php中似乎没有parse_url的逆向函数来讲一个解析出来的数组组合成url字符串,只有一个http_build_query用来将数组 ...

  2. linux上mysql安装

    所有平台的MySQL下载地址为: MySQL 下载. 挑选你需要的 MySQL Community Server 版本及对应的平台. MySQL - MySQL服务器.你需要该选项,除非你只想连接运行 ...

  3. Django--初始化

    1.Django介绍 它是一个WEB框架 Django--大而全 tornado.flask--小而精 2.Django安装 https://www.djangoproject.com/downloa ...

  4. 【Leetcode009】Palindrome Number

    问题链接:https://leetcode.com/problems/palindrome-number/#/description Question:Determine whether an int ...

  5. (转)常见存储过程分页PK赛——简单测试分析常见存储过程分页速度

    原文地址:http://www.cnblogs.com/yangyy753/archive/2013/01/23/2872753.html 数据的分页是我们再熟悉不过的功能了,各种各样的分页方式层出不 ...

  6. SQL 2005报错之Restore fail for Server 'DatabaseServerName'.

    Restore fail for Server 'DatabaseServerName'.(Microsoft.SqlServer.Smo) Additional information: Syste ...

  7. 排序算法汇总(java实现,附源代码)

    整理系统的时候发现了原来写的各种算法的总结,看了一下,大吃一惊,那时候的我还如此用心,具体的算法,有的已经模糊甚至忘记了,看的时候就把内容整理出来,顺便在熟悉一下,以后需要的时候就可以直接过来摘抄了. ...

  8. C#分布式存储演练(提供项目下载)

    C#简单的演练了一下分布式的存储,学习fastdns的结构,Client向ProcessCenter请求Storage的服务,然后上传文件. 分布式服务就是多个服务器作为客户端互相[配合],要中心化就 ...

  9. 关于 href="\\#" 和 return false

    href="\\#"  跳转到本页 return false 相当于不刷新 href="javascript:void(0)"   或者 href=" ...

  10. 细说Mammut大数据系统测试环境Docker迁移之路

    欢迎访问网易云社区,了解更多网易技术产品运营经验. 前言 最近几个月花了比较多精力在项目的测试环境Docker迁移上,从最初的docker"门外汉"到现在组里的同学(大部分测试及少 ...