字典树。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<algorithm>
using namespace std;const int maxn=1000000+10;
const int maxm=40;
struct Node
{int f;int son[2];int num;
}node[20*maxn];
int tot;int n,a[maxn],k;
long long ans;
int r[maxm];int add(int x)
{node[tot].f=x;node[tot].num=0;node[tot].son[0]=-1;node[tot].son[1]=-1;tot++;return tot-1;
}long long get(int x)
{int h=0,base[maxm]; memset(base,0,sizeof base);while(x) base[h++]=x%2,x=x/2;long long res=0;int p=0;for(int i=maxm-5;i>=0;i--){if(r[i]==0){if(base[i]==0){if(node[p].son[1]!=-1)res=res+(long long)node[node[p].son[1]].num;p=node[p].son[0];if(p!=-1&&i==0) res=res+node[p].num;if(p==-1) break;}else{if(node[p].son[0]!=-1)res=res+(long long)node[node[p].son[0]].num;p=node[p].son[1];if(p!=-1&&i==0) res=res+node[p].num;if(p==-1) break;}}else if(r[i]==1){if(base[i]==0){p=node[p].son[1];if(p!=-1&&i==0) res=res+node[p].num;if(p==-1) break;}else{p=node[p].son[0];if(p!=-1&&i==0) res=res+node[p].num;if(p==-1) break;}}}return res;
}void update(int x)
{int h=0,base[maxm]; memset(base,0,sizeof base);while(x) base[h++]=x%2,x=x/2;int p=0;for(int i=maxm-5;i>=0;i--){if(node[p].son[base[i]]==-1)node[p].son[base[i]]=add(base[i]);p=node[p].son[base[i]];node[p].num++;}
}void init()
{ans=0;tot=0;add(-1);// root 0for(int i=1;i<=maxm-4;i++) node[i-1].son[0]=add(0);for(int i=1;i<tot;i++) node[i].num=1;memset(r,0,sizeof r);int v=0; while(k) r[v++]=k%2,k=k/2;
}int main()
{scanf("%d%d",&n,&k);for(int i=1;i<=n;i++) scanf("%d",&a[i]);init();int c=0;for(int i=1;i<=n;i++){c=c^a[i];ans=ans+get(c);update(c);}printf("%lld\n",ans);return 0;
}

转载于:https://www.cnblogs.com/zufezzt/p/5630759.html

codeforces 665E Beautiful Subarrays相关推荐

  1. cf 665E - Beautiful Subarrays

    One day, ZS the Coder wrote down an array of integers a with elements a1,  a2,  -,  an. A subarray o ...

  2. E. Beautiful Subarrays(思维 01 trie 树)

    E. Beautiful Subarrays 思路 显然有ai⨁ai+1⨁--⨁an=(a1⨁a2⨁--⨁an)⨁(a1⨁a2⨁--⨁ai−1)a_i\bigoplus a_{i + 1} \bigo ...

  3. 【CodeForces 1265C --- Beautiful Regional Contest】

    [CodeForces 1265C --- Beautiful Regional Contest] 题目来源:点击进入[CodeForces 1265C - Beautiful Regional Co ...

  4. 【CF665E】 Beautiful Subarrays

    题目 展开 题目描述 One day, ZS the Coder wrote down an array of integers aa with elements a_{1},a_{2},-,a_{n ...

  5. CodeForces - 55D Beautiful numbers

    题目链接:http://codeforces.com/problemset/problem/55/D 题意:求区间[L,R]有多少个Beautiful numbers.Beautiful number ...

  6. Codeforces 1093D Beautiful Graph

    题目链接:http://codeforces.com/contest/1093/problem/D 第一次做这种题目,染色+组合数学.. 假设这个图里有奇数环,那么肯定是不行的,因为无论怎么样都是偶数 ...

  7. Codeforces 55D Beautiful Number (数位统计)

    把数位dp写成记忆化搜索的形式,方法很赞,代码量少了很多. 下面为转载内容:  a positive integer number is beautiful if and only if it is  ...

  8. Codeforces 55D Beautiful numbers (数位DP)

    题意:有T组询问,每次询问区间[l, r]中的beautiful number有多少.beautiful number是指这个数可以被组成它的数字整除.例如15是beautiful number,因为 ...

  9. CodeForces 893B Beautiful Divisors (打表)

    题目大意:最近,Luba了解了一种特殊的数字,他称之为"漂亮的数字".这个数被称为漂亮是因为它的二进制表示包括k+1个连续的,然后是k个连续的0. Some examples of ...

  10. CodeForces - 893B Beautiful Divisors(数学,二进制)

    Description Recently Luba learned about a special kind of numbers that she calls beautiful numbers. ...

最新文章

  1. Java集合,ConcurrentHashMap底层实现和原理(常用于并发编程)
  2. 凌琦:物联网——一场正在发生的变革
  3. 在Linux上编译安装php开发环境(install mysql5.6)-3
  4. git 提交命令_工作总结:Git的学习和使用,最详细的Git教程,从入门到精通
  5. 参数校验放在controller还是service_@Validated校验的实践
  6. win服务器创建文件夹命令,Win10系统如利用命令提示符或WSL创建任意大小空白文件...
  7. java 友元_C++ 友元函数 | 菜鸟教程
  8. 父组件给子组件传值方法_【Vue】小学生都能看懂的子父组件传值
  9. linux 查看cuda版本_Ubuntu18.04+Tensorflow GPU版本环境搭建
  10. bat调用ant_bat调用ant_Ant调用批处理文件编译VS2005程序
  11. Python2.7版本的pip下载安装(win7 64位,Python2.7)
  12. matlab软件moran值,MATLAB 的moran,LM值
  13. 利用python和pygame模块实现飞机大战
  14. STM32F103驱动四位共阳极数码管程序
  15. 腾讯QQ被盗的形式及密码保护技巧(转)
  16. php_version_too_low,以太坊常见问题和错误 / Web3j error:Intrinsic gas too low - 汇智网
  17. 面向对象程序设计c++版董正言张聪课本课后习题答案第四章
  18. python图像的几何运算_《计算机视觉》中的几何变换:Python示例的直观解释
  19. Python编程:从入门到实践(读书笔记:第6章 字典)
  20. Lua脚本如何调用C/C++模块,Windows以及Linux版本演示

热门文章

  1. 煤岩分析仪测定煤的镜质体反射率和煤显微组分
  2. 智能优化算法:社交网络搜索算法-附代码
  3. 机器学习笔记-回归评价指标scikit-learn
  4. MFC获取当前应用程序实例句柄的三种方法
  5. 联通实时计算平台演进与实践
  6. 京东搜索排序在线学习的 Flink 优化实践
  7. Apache Flink Meetup ·上海站精彩回顾(附PPT下载)
  8. 为什么大家都说 SELECT * 效率低
  9. 朋友圈疯转的“佩奇”是啥?用 Python 画个小猪佩奇来告诉你
  10. iphone投屏ipad_幕享免费无线投屏:你朝思暮想的屏幕互联方式