CF1109A Sasha and a Bit of Relax

  • 用 \(xorsum[l,r]\) 表示 \(a[l] \oplus a[l+1] \oplus a[l+2]... a[r-1] \oplus a[r]\).
  • 则数对 \((l,r)\) 满足 \(xorsum[l,mid]=xorsum[mid+1,r]\ and\ 2|(r-l).\)而

\[xorsum[l,mid]=xorsum[mid+1,r]\\ \Leftrightarrow
xorsum[l,r]=0\\ \Leftrightarrow
xorsum[1,l-1]=xorsum[1,r].
\]

  • 于是只需开两个桶,分别记录奇数偶数位置上的 \(xor\) 前缀和出现次数.
  • 注意开始时 \(0\) 也在偶数位上出现了,需加入桶中.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pii pair<int,int>
inline int read()
{
int x=0;
bool pos=1;
char ch=getchar();
for(;!isdigit(ch);ch=getchar())
if(ch=='-')
pos=0;
for(;isdigit(ch);ch=getchar())
x=x*10+ch-'0';
return pos?x:-x;
}
int odd[(1<<20)+10],even[(1<<20)+10];
int main()
{
int xorsum=0;
int n=read();
ll ans=0;
++even[0];
for(int i=1;i<=n;++i)
{
int x=read();
xorsum^=x;
if(i&1)
{
ans+=odd[xorsum];
++odd[xorsum];
}
else
{
ans+=even[xorsum];
++even[xorsum];
}
}
cout<<ans<<endl;
return 0;
}

CF1109A 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. Sasha and a Bit of Relax(前缀异或和+二维数组+思维)

    Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and ...

  3. Codeforces 1113C: Sasha and a Bit of Relax(位运算|异或)

    time limit per test: 1 secondmemory limit per test: 256 megabytesinput: standard inputoutput: standa ...

  4. Codeforces Round #539 (Div. 2) C Sasha and a Bit of Relax

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

  5. cf——Sasha and a Bit of Relax(dp,math)

    关于异或运算,是可以求前缀和的.还有一些异或运算的性质 0^a=a; 交换律 a^b=b^a 结合律 a^(b^c)=(a^b)^c 分配率 a^(b+c)=a^b+a^c 自反律 a^b^b=a 判 ...

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

  7. Codeforces Round #539 Div1 题解

    Codeforces Round #539 Div1 题解 听说这场很适合上分QwQ 然而太晚了QaQ A. Sasha and a Bit of Relax 翻译 有一个长度为\(n\)的数组,问有 ...

  8. Codeforces Round #539 (Div. 2)

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

  9. Codeforces Round #539&#542&#543&#545 (Div. 1) 简要题解

    Codeforces Round #539 (Div. 1) A. Sasha and a Bit of Relax description 给一个序列\(a_i\),求有多少长度为偶数的区间\([l ...

随机推荐

  1. 使用size_t注意边界

    C++中的 size_t 表示数组的下标,一般为: typedef unsigned size_t; 在学习中我们一般使用int表示下标,这样在循环中可以判断边界x>=0 或x<=0,比如 ...

  2. 面试代码基础(一)从strstr说起

    对于写程序要注意:要能在面试官的提示下把代码写出来(把思想实现的能力)!还要注意边界检查!递归找到出口! 开场来个简单字符串匹配 int strstr(char* target,char* sourc ...

  3. 【转】asp.net 项目在 IE 11 下出现 “__doPostBack”未定义 的解决办法

    最近我们运营的网站有用户反馈在 IE 11 下<asp:LinkButton> 点击出现 “__doPostBack”未定义”,经过一番google,终于知道了原因:ASP.NET 可能无 ...

  4. Struts 2 + Hibernate + Spring 整合要点

    Struts 2 和 Spring 的功能有重合,因此有必要说明下,整合中分别使用了两种框架的哪些技术. Struts 2 使用功能点: 1.拦截器.一处是对非登录用户购物进行拦截,一处是对文件上传的 ...

  5. MySQL索引最左原则

    通过实例理解单列索引.多列索引以及最左前缀原则 实例:现在我们想查出满足以下条件的用户id: 因为我们不想扫描整表,故考虑用索引. 单列索引: ALTER TABLE people ADD INDEX ...

  6. Sql类型

    1.varchar和nvarchar的区别:varchar(n)长度为n个字节的可变长度且非Unicode的字符数据.n 必须是一个介于 1 和 8,000 之间的数值.存储大小为输入数据的字节的实际 ...

  7. 构建hadoop集群时遇到的问题

    在构建hadoop集群时,出现过主节点中的namenode或datanode启动不成功的问题.在日志文件中往往会显示namenode和datanode中clusterID不相同的问题,这个问题往往都是 ...

  8. android AVD启动失败原因之一

    在mac上安装好Android SDK.AVD及相关的组件之后,手动创建了一个安卓模拟器后,通过actions启动,会弹出一个提示窗口,然后就闪退,也没有报错什么的,在网上搜了半天AVD启动失败的问题 ...

  9. 解决boot空间不足问题

    uname -a :查看现在系统信息,内核版本 dpkg --get-selections |grep linux-image : 查看内核列表 sudo apt-get remove linux-i ...

  10. torch7框架 深度学习(1)

    前面已经安装好了torch,下面就来看看如何在torch框架上搭建深度学习模型,我一直觉得源码结合原理是机器学习最好的学习途径.所以我们从分析一个简单的案例开始吧. 参考Supervised Lear ...