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 ...
随机推荐
- cglib动态代理(需导入cglib-nodep-2.1_3.jar)
public interface AnimalInterface { public void cry(); } public class AnimalImpl implements AnimalInt ...
- spring mvc: xml练习
xml练习,得到的结果是: <?xml version="1.0" encoding="UTF-8" standalone="yes" ...
- linux正则表达式回忆记录
好久没用linux grep相关正则表达式,现在简单记录下. grep简介 grep 是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来.通常grep有三种版本grep.egr ...
- 编码转换 Native / UTF-8 / Unicode
Native/Unicode Native 这是一个例子,this is a example Unicode 这是一个例子,this is a example Native/UTF-8 Nativ ...
- Bootstrap 与 IE 兼容模式 关系讲解
IE 兼容模式 Bootstrap 不支持 IE 古老的兼容模式.为了让 IE 浏览器运行最新的渲染模式下,建议将此 <meta> 标签加入到你的页面中:Copy <meta htt ...
- cordova安卓sdk
Android SDK在线更新镜像服务器来下载安装: 1.北京化工大学镜像服务器地址: IPv4: ubuntu.buct.edu.cn/ 端口:80 IPv4: ubuntu.buct.cn/ 端口 ...
- Back Track5学习笔记
1.BT5默认用户名:root.密码:toor(公司是yeslabccies) 2.进入图形化界面命令:startx 3.更改密码:sudo passwd root 扫描工具 第一部分网络配置: 4. ...
- jQuery-轮播图(友善滴滚动切换)
线上实例:http://lgy.1zwq.com/slide/ [处理] 这里的图片滚动轮播,做了点小处理:当在第1页状态时,你点击第5页,图片的滚动是一张滑过,而不是从2-3-4-5(这种的多张滚动 ...
- js中删除数组中某一项的方法
1:js中的splice方法 splice(index,len,[item]) 注释:该方法会改变原始数组. splice有3个参数,它也可以用来替换/删除/添加数组内某一个或者几个值 inde ...
- IOS-网络(网页开发-UIWebView,HTML,CSS,JavaScript,OC和JS代码互调)
一.网页基础 // // ViewController.m // IOS_0218_网页开发1 // // Created by ma c on 16/2/18. // Copyright © 201 ...