题中意思显而易见,即求满足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. Lombok使用简介

    1.在maven中加入Lombok引入 2.在开发环境中加入Lombok插件 3.在实体类的类名上增加注释@Date即可使用所有get,set方法

  2. node note

    1.关于next() next()函数接受一个Error对象,在判断错误时,返回这个next()函数,并传入自定义的Error对象可以被向下捕捉,你也可以自定义统一捕捉错误Error的中间件,在app ...

  3. Mybatis useGeneratedKeys 填充自增主键值(使用Mysql)的原理分析

    一.Mybatis配置 <insert id="insert" parameterType="com.test.TestDO" keyProperty=& ...

  4. 词根:sol = sun(太阳) 词根:sol = alone/single, whole/entire (单独的)

    词根:sol = sun(太阳) sol 这个词根有的书上如刘毅字典,刘洪波英文字根词源精讲等上面说来自拉丁语的sol(=sun),有的书如赢在单词上面说sol 来自拉丁语的solari,但不管哪种说 ...

  5. iOS获取崩溃日志

    重要提示:  此文档不再更新.有关Apple SDK的最新信息,请访问文档网站. 来源: https://developer.apple.com/library/archive/qa/qa1747/_ ...

  6. LeetCode解题录-51~100

    [leetcode]51. N-QueensN皇后    Backtracking Hard [leetcode]52. N-Queens II N皇后 Backtracking Hard [leet ...

  7. vue父子组件实现v-model

    话不多说,直接上代码 <div id="app"> <price-input v-bind:value="price" v-on:input= ...

  8. 转:Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-j8m0mf5q/mysqlclient

    错误场景 第一次部署服务器时mysqlclient安装失败 思考 初步考虑是pip没有升级,最后发现不是这个原因. 解决办法 来源:https://blog.csdn.net/mr_tia/artic ...

  9. stark组件开发之组合搜索页面效果和 URL

    页面效果,只是样式.这个好解决!yield 的时候. 返回几个样式出去就好了! 并且前端写上一些样式的css {% if search_group_row_list %} <div class= ...

  10. 12.Redis运维点

    12.Redis运维点12.1 Linux配置优化12.1.1 内存分配控制12.1.2 swappiness12.1.3 THP12.1.4 OOM killer12.1.5 使用NTP12.1.6 ...