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. photoshop cc下载与安装

    地址:https://jingyan.baidu.com/article/c275f6bacdd927e33d756729.html

  2. 字体渲染技术(字体抗锯齿技术) -webkit-font-smoothing: antialiased;

    1.-webkit-font-smoothing控制的字体渲染只对MacOS的webkit有效.所以,你在MacOS测试环境下面设置-webkit-font-smoothing时,只要你不把它设置为n ...

  3. Linux加载/usr/local/lib中的so库

    > https://my.oschina.net/u/2306127/blog/1617233 > https://blog.csdn.net/csfreebird/article/det ...

  4. 备注Quartz触发器设置

    corn表达式时间格式: <!-- s m h d m w(?) y(?) -->, 分别对应: 秒>分>小时>日>月>周>年, ●星号(*):可用在所 ...

  5. KVM与XEN虚拟化环境究竟有何不同

    虚拟化的概念在近些年收到了很大程度上的普及,求其原因很简单:虚拟化能够最大程度利用资源,为企业节约成本.目前市面较受欢迎的虚拟架构主要有KVM.XEN和VMware,其中,KVM和XEN都是免费开源的 ...

  6. Lua学习笔记1,基本数据类型

    1.字符串的连接使用的是  .. ,如 print(123 .. 44) 输出 12344 print ('a' .. 'b') 输出 ab print(123 .. 44)这句的时候 .. 两边要空 ...

  7. linux命令权限

    linux-命令权限 1)   新建用户natasha,uid为1000,gid为555,备注信息为“master” 2)   修改natasha用户的家目录为/Natasha 3)   查看用户信息 ...

  8. js中的真值和假值

    大多数编程语言中,布尔值true和false仅仅表示true/false.JavaScript中,如'Hello‘这样的字符串值,也可以看做true. 以下是不同数据类型在JavaScript中是如何 ...

  9. hdu 5800 To My Girlfriend(背包变形)

    To My Girlfriend Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  10. wget 认知及常用命令【转载】

    https://www.cnblogs.com/lxz88/p/6278268.html https://www.cnblogs.com/cindy-cindy/p/6847502.html