题中意思显而易见,即求满足al⊕al+1⊕…⊕amid=amid+1⊕amid+2⊕…⊕ar且l到r的区间长为偶数的这样的数对(l,r)的个数。

若al⊕al+1⊕…⊕amid=amid+1⊕amid+2⊕…⊕ar,我们可以推出al⊕al+1⊕…⊕amiamid+1⊕amid+2⊕…⊕ar=0;反推也是可以成立的。

我们已知任何数0对异或都等于本身。所以当前数异或一段数之后等于本身,那么异或之后的这段数肯定是异或为0的,我们只需要知道这一段是不是长度为偶数即可。

我们从头异或一道,若异或到某个数之后这个数在曾经出现过,我们就加上它可组成偶数段所有出现的次数即可。若全部异或为0,也是一种情况,我们假设0一开始也出现一次就好了。

用两个map统计奇偶(代码就能看懂)

 #include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
map<ll,ll>p1;
map<ll,ll>p2;
ll a[];
int main()
{
ll n,t,k,i,j;
while(scanf("%I64d",&n)!=EOF)
{
k=;
p1.clear();
p2.clear();
scanf("%I64d",&j);
p2[j]=;
p1[]=;
for(i=;i<n;i++)
{
scanf("%I64d",&t);
j^=t;
if(i%==)
{
if(p2[j]!=)
k+=p2[j];
p2[j]++;
}
else
{ if(p1[j]!=)
k+=p1[j]; p1[j]++;
}
}
printf("%I64d\n",k);
}
}

Codeforces Round #539 (Div. 2) C Sasha and a Bit of Relax的更多相关文章

  1. Codeforces Round #539 (Div. 2) - C. Sasha and a Bit of Relax(思维题)

    Problem   Codeforces Round #539 (Div. 2) - C. Sasha and a Bit of Relax Time Limit: 2000 mSec Problem ...

  2. 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 ...

  3. Codeforces Round #539 (Div. 2) - D. Sasha and One More Name(思维)

    Problem   Codeforces Round #539 (Div. 2) - D. Sasha and One More Name Time Limit: 1000 mSec Problem ...

  4. Codeforces Round #539 (Div. 1) C. Sasha and a Patient Friend 动态开点线段树

    题解看这里 liouzhou_101的博客园 更简洁的代码看这里: #include <bits/stdc++.h> using namespace std; typedef long l ...

  5. Codeforces Round #539 (Div. 1) E - Sasha and a Very Easy Test 线段树

    如果mod是质数就好做了,但是做除法的时候对于合数mod可能没有逆元.所以就只有存一下mod的每个质因数(最多9个)的幂,和剩下一坨与mod互质的一部分.然后就能做了.有点恶心. CODE #incl ...

  6. Codeforces Round #539 (Div. 1) 1109F. Sasha and Algorithm of Silence's Sounds LCT+线段树 (two pointers)

    题解请看 Felix-Lee的CSDN博客 写的很好,不过最后不用判断最小值是不是1,因为[i,i]只有一个点,一定满足条件,最小值一定是1. CODE 写完就A,刺激. #include <b ...

  7. Codeforces Round #539 (Div. 2)

    Codeforces Round #539 (Div. 2) A - Sasha and His Trip #include<bits/stdc++.h> #include<iost ...

  8. Codeforces Round #539 (Div. 2) 题解

    Codeforces Round #539 (Div. 2) 题目链接:https://codeforces.com/contest/1113 A. Sasha and His Trip 题意: n个 ...

  9. Codeforces Round #373 (Div. 2) E. Sasha and Array 线段树维护矩阵

    E. Sasha and Array 题目连接: http://codeforces.com/contest/719/problem/E Description Sasha has an array ...

随机推荐

  1. JEECG 3.7.8 新版表单校验提示风格使用&升级方法(validform 新风格漂亮,布局简单)

    JEECG 表单校验采用的是validform,默认的校验提示需要占用页面布局,提示效果较传统.jeecg这个自定义的校验提示风格,不占用页面布局,提示效果也更美观,简单易用,让表单看起来更漂亮!!! ...

  2. 49.字符串转int

    面360的时候这道题目加了一个要求就是要求小数输出整数,故增加一个关于小数点的判断 要注意转义字符:"."和"|"都是转义字符,必须得加"\\&quo ...

  3. 回溯法 17. Letter Combinations of a Phone Number

    class Solution { public: map<char,string> dict; vector<string> letterCombinations(string ...

  4. 同步pod时区与node主机保持一致

    一.通过环境变量设置 apiVersion: v1 kind: Pod metadata: name: pod-env-tz spec: containers: - name: ngx image: ...

  5. Ubuntu搜狗拼音输入法崩溃问题

    Ubuntu 14.04.5 LTS 环境下搜狗拼音经常崩溃,似乎也没有什么特别好的解决办法. 以下是重启命令 #!/bin/sh >/dev/>& >/dev/>&a ...

  6. yarn安装及node升级

    ERROR: root@debian:/home/test/keygen-radio-master/scripts# npm install -g yarn npm WARN engine yarn@ ...

  7. Adobe Flash player ActiveX下载地址

    http://www.adobe.com/support/flashplayer/downloads.html http://download.macromedia.com/pub/flashplay ...

  8. mysqli链接数据库

    <?php $uid = $_GET['uid']; $host = 'localhost';$database = 'test';$username = 'root';$password = ...

  9. CodeWarrior 10 配置Jlint初始化文件

    新建一个项目之后,飞思卡尔的仿真器的配置不如德州仪器那么简单.他需要一些配置. 当我们新建一个工程后,可以采取如下步骤配置Jlint: 1.右击工程名,选择属性. 2.在Run/Debug Setti ...

  10. Java基础(命令行操作、注释及API、)

    一.常用的dos命令. dir:列出当前目录下的文件及文件夹 md:创建目录 rd:删除目录 cd:进入到指定目录 cd..:退出到上一级目录 cd\:退出到根目录 del:删除文件 exit:退出d ...