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. SpringMvc 笔记

    整理出来是 SpringMvc 笔记 方便以后查询 框架太多了 不经常使用 忘记的可能性很大 自己整理一套笔记 一看就明白了 1 对比 原始请求响应流程 1 发送请求 --> 2 控制层 --& ...

  2. C# Memcached 缓存

    之前做的功能,程序可能有不足之处,但还是要记录下 ICacheStrategy.cs文件 public interface ICacheStrategy { /// <summary> / ...

  3. 仿照Chome的GhostPage调试功能

    今天在测试过程中发现了网站的一个bug,在大屏幕上是自适应的,小屏幕笔记本上高度不是自适应,html的高度并不是浏览器的高度,小屏幕总是差了一截,在调试过程中偶然发现差的那一小截正好是一个横向滑动条的 ...

  4. thinkphp getField("xxxxx", true); 得到一个字段所有值组成的的数组

    很多时候我们只需要一张表里某个字段的值,组成的数组 $Channel = D('channel');$channelList = $Channel->order('user_name')-> ...

  5. (3) iOS开发之UI处理-UIView篇

    在UIView作为许多子控件的容器的时候,首先我们需要动态的计算出UIView下的所有子控件的高度,并布局排列好,然后我们还要把作为容器的UIView的高度调整到刚好包裹着所有子控件,不会过矮,也不会 ...

  6. JQuery对象与javascript对象的转换

    jQuery 对象是通过 jQuery 包装DOM 对象后产生的对象. jQuery 对象是 jQuery 独有的,其可以使用 jQuery 里的方法,但是不能使用 DOM 的方法:例如: $(&qu ...

  7. Python 序列化pickle/cPickle模块整理

    Python序列化的概念很简单.内存里面有一个数据结构,你希望将它保存下来,重用,或者发送给其他人.你会怎么做?这取决于你想要怎么保存,怎么重用,发送给谁.很多游戏允许你在退出的时候保存进度,然后你再 ...

  8. 小练习:Two Sum

    1.example Given nums = [, , , ], target = , Because nums[] + nums[] = + = , , ]. 2.solve class Solut ...

  9. LeetCode OJ:Swap Nodes in Pairs(成对交换节点)

    Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2-&g ...

  10. compass框架的sprite雪碧图的用法简要

    ---恢复内容开始--- **简介** CSS SPRITE 即 CSS雪碧,即是将诸多图片合成一张图片,然后使用CSS 的background和background-position属性渲染. 这样 ...