CF1109A Sasha and a Bit of Relax
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,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的更多相关文章
- 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 ...
- Sasha and a Bit of Relax(前缀异或和+二维数组+思维)
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and ...
- Codeforces 1113C: Sasha and a Bit of Relax(位运算|异或)
time limit per test: 1 secondmemory limit per test: 256 megabytesinput: standard inputoutput: standa ...
- 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 ...
- 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 判 ...
- 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 ...
- Codeforces Round #539 Div1 题解
Codeforces Round #539 Div1 题解 听说这场很适合上分QwQ 然而太晚了QaQ A. Sasha and a Bit of Relax 翻译 有一个长度为\(n\)的数组,问有 ...
- Codeforces Round #539 (Div. 2)
Codeforces Round #539 (Div. 2) A - Sasha and His Trip #include<bits/stdc++.h> #include<iost ...
- Codeforces Round #539Ȟȟȡ (Div. 1) 简要题解
Codeforces Round #539 (Div. 1) A. Sasha and a Bit of Relax description 给一个序列\(a_i\),求有多少长度为偶数的区间\([l ...
随机推荐
- 物料类型AM11没有任务清单类型N定义
CA01 创建工艺路线时报错信息:“物料类型AM11没有为任务清单类型N定义” (如下图) 处理方法: 配置路径:生产->基本数据->工艺路线->通用数据->定义物料类型分配 ...
- spring boot 笔记--第三章
spring boot 笔记 第三章,使用Spring boot 构建系统: 强烈建议支持依赖管理的构建系统,Maven或Gradle 依赖管理: Spring Boot的每版本都会提供它支持的依赖列 ...
- spring的静态代理和动态代理
Java静态代理 Jdk动态代理 java代理模式 即Proxy Pattern,23种java常用设计模式之一.代理模式的定义:对其他对象提供一种代理以控制对这个对象的访问. 原理: 代理模式的主要 ...
- linux ps 命令参数详解
-a 显示所有终端机下执行的进程,除了阶段作业领导者之外. a 显示现行终端机下的所有进程,包括其他用户的进程. -A 显示所有进程. -c 显示CLS和PRI栏位. c 列出进程时,显示每个进程真正 ...
- C#多线程3种创建Thread、Delegate.BeginInvoke、线程池
1 创建多线程,一般情况有以下几种:(1)通过Thread类 (2)通过Delegate.BeginInvoke方法 (3)线程池 using System; using System.C ...
- Android6.0------权限申请~easypermissions
前面写了Android6.0权限介绍和权限单个,多个申请,用的是纯Java代码,本文主要说的是借助第三方库来实现权限申请. 借助第三方库 easypermissions来申请6.0权限,Google官 ...
- poj2823单调队列
这个裸题,滑动窗口求最大最小值,单调队列来两边,一次单调递增q[s]就是最小值,一次单调递减q[s]就是最大值 cin会超时,解除同步也没用... #include<map> #inclu ...
- POJ 1160 经典区间dp/四边形优化
链接http://poj.org/problem?id=1160 很好的一个题,涉及到了以前老师说过的一个题目,可惜没往那上面想. 题意,给出N个城镇的地址,他们在一条直线上,现在要选择P个城镇建立邮 ...
- qt5.2.1在linux下去除最大化和最小化按钮
#include <QtGui/QGuiApplication> #include <QDebug> #include <QScreen> #include &qu ...
- Using Oracle Database In-Memory with Oracle E-Business Suite
Database In-Memory is one of a number of options that can be deployed to address Oracle E-Business S ...