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+2⊕…⊕ar,我们可以推出al⊕al+1⊕…⊕amiamid+1⊕amid+2⊕…⊕ar=0;反推也是可以成立的。
我们已知任何数0对异或都等于本身。所以当前数异或一段数之后等于本身,那么异或之后的这段数肯定是异或为0的,我们只需要知道这一段是不是长度为偶数即可。
我们从头异或一道,若异或到某个数之后这个数在曾经出现过,我们就加上它可组成偶数段所有出现的次数即可。若全部异或为0,也是一种情况,我们假设0一开始也出现一次就好了。
用两个map统计奇偶(代码就能看懂)
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
map<ll,ll>p1;
map<ll,ll>p2;
ll a[];
int main()
{
ll n,t,k,i,j;
while(scanf("%I64d",&n)!=EOF)
{
k=;
p1.clear();
p2.clear();
scanf("%I64d",&j);
p2[j]=;
p1[]=;
for(i=;i<n;i++)
{
scanf("%I64d",&t);
j^=t;
if(i%==)
{
if(p2[j]!=)
k+=p2[j];
p2[j]++;
}
else
{ if(p1[j]!=)
k+=p1[j]; p1[j]++;
}
}
printf("%I64d\n",k);
}
}
Codeforces Round #539 (Div. 2) C 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 ...
- 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 (Div. 2) - D. Sasha and One More Name(思维)
Problem Codeforces Round #539 (Div. 2) - D. Sasha and One More Name Time Limit: 1000 mSec Problem ...
- Codeforces Round #539 (Div. 1) C. Sasha and a Patient Friend 动态开点线段树
题解看这里 liouzhou_101的博客园 更简洁的代码看这里: #include <bits/stdc++.h> using namespace std; typedef long l ...
- Codeforces Round #539 (Div. 1) E - Sasha and a Very Easy Test 线段树
如果mod是质数就好做了,但是做除法的时候对于合数mod可能没有逆元.所以就只有存一下mod的每个质因数(最多9个)的幂,和剩下一坨与mod互质的一部分.然后就能做了.有点恶心. CODE #incl ...
- Codeforces Round #539 (Div. 1) 1109F. Sasha and Algorithm of Silence's Sounds LCT+线段树 (two pointers)
题解请看 Felix-Lee的CSDN博客 写的很好,不过最后不用判断最小值是不是1,因为[i,i]只有一个点,一定满足条件,最小值一定是1. CODE 写完就A,刺激. #include <b ...
- 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. 2) 题解
Codeforces Round #539 (Div. 2) 题目链接:https://codeforces.com/contest/1113 A. Sasha and His Trip 题意: n个 ...
- Codeforces Round #373 (Div. 2) E. Sasha and Array 线段树维护矩阵
E. Sasha and Array 题目连接: http://codeforces.com/contest/719/problem/E Description Sasha has an array ...
随机推荐
- python setup.py 包含静态文件及模板文件
package_data 和MANIFEST.in都写,include_package_data=True https://stackoverflow.com/a/3597263/8025086
- web中ios移动端软键盘收起后,页面内容留白不下滑
微信里面打开web页面,在ios软键盘收起时,页面键盘位置的内容留白,如下图 这个问题纠结了很久,然后请教了老大(威哥),看到页面老大给出的方案就是代码改变滚动条的位置. 这里就监听键盘收起的事件,来 ...
- React Native: unable to load scripts from assets 'index.android.bundle' on real device
问题:重新建了一个项目后,运行react-native run-android报: unable to load scripts from assets 'index.android.bundle' ...
- Rsync + Lsyncd服务实现文件实时同步/备份
1.接受端安装rsync yum -y install rsync 2.配置同步模块 vim /etc/rsyncd.conf # any name you like [backup] # desti ...
- react学习2
props,state与render函数的关系 react,父组件的state中的变量改变,则相应的render函数也会执行,返回新的视图,同时父组件的子组件通过props获取父组件的state的变量 ...
- 管理多个gradle,SDKMAN
背景:同一台机器上有两个app需要编译,但是两个app的gradle版本不一致,所以需要安装一个管理gradle版本的工具 sdkman:(Software Development Kit Man ...
- Python人工智能第二篇
Python人工智能之路 - 第二篇 : 现成的技术 预备资料: 1.FFmpeg: 链接:https://pan.baidu.com/s/1jonSAa_TG2XuaJEy3iTmHg 密码:w ...
- Android使用scrollview截取整个的屏幕并分享微信
先看看截图效果图 截取scrollview的屏幕 /** * 截取scrollview的屏幕 **/ public static Bitmap getScrollViewBitmap(ScrollVi ...
- 15. 3Sum (JAVA)
Given an array nums of n integers, are there elements a, b, cin nums such that a + b + c = 0? Find a ...
- 企业BGP网络规划案例(四)
关于路由的发布和接收使用route-map过滤,防止本AS作为一个转发区域. 在XRV3上和XRV4上使用prefix-list 进行路由接搜和发布的过滤 XRV3配置 =============== ...