做法

求出答案序列的异或前缀和\(sum_i\),\([l,r]\)子段异或和可表示为\(sum_r\bigoplus sum_{l-1}\)

故转换问题为,填\(sum\)数组,数组内的元素不为\(0\)且互不相同,且两两异或不为\(x\)

预处理\(x\)为多对值,每对值异或起来为\(x\),显然是两两互不影响的,每对值选择任意一个填就行了

最后还得从\(sum_i=\bigoplus_{j=1}^i a_i\)转换为\(a_i\)

code

#include<bits/stdc++.h>
using namespace std;
typedef int LL;
const LL maxn=2e6+9;
inline LL Read(){
LL x(0),f(1); char c=getchar();
while(c<'0' || c>'9'){
if(c=='-') f=-1; c=getchar();
}
while(c>='0' && c<='9'){
x=(x<<3)+(x<<1)+c-'0'; c=getchar();
}return x*f;
}
LL n,x,tot,sum;
LL to[maxn],visit[maxn],ans[maxn];
vector<LL> e;
int main(){
n=Read(); x=Read();
LL up(1<<n);
e.push_back(0);
visit[x]=1;
for(LL i=1;i<up;++i){
if(visit[i]) continue;
visit[x^i]=1;
e.push_back(i);
}
printf("%d\n",e.size()-1);
for(LL i=1;i<e.size();++i) printf("%d ",e[i]^e[i-1]);
return 0;
}

CF1174D Ehab and the Expected XOR Problem(二进制)的更多相关文章

  1. CF1174D Ehab and the Expected XOR Problem

    思路: 使用前缀和技巧进行问题转化:原数组的任意子串的异或值不能等于0或x,可以转化成前缀异或数组的任意两个元素的异或值不能等于0或x. 实现: #include <bits/stdc++.h& ...

  2. 【CF1174D】 Ehab and the Expected XOR Problem - 构造

    题面 Given two integers \(n\) and \(x\), construct an array that satisfies the following conditions: · ...

  3. CF D. Ehab and the Expected XOR Problem 贪心+位运算

    题中只有两个条件:任意区间异或值不等于0或m. 如果只考虑区间异或值不等于 0,则任意两个前缀异或值不能相等. 而除了不能相等之外,还需保证不能出现任意两个前缀异或值不等于m. 即 $xor[i]$^ ...

  4. codeforces#1157D. Ehab and the Expected XOR Problem(构造)

    题目链接: http://codeforces.com/contest/1174/problem/D 题意: 构造一个序列,满足以下条件 他的所有子段的异或值不等于$x$ $1 \le a_i< ...

  5. Codeforces Round #525 (Div. 2)D. Ehab and another another xor problem

    D. Ehab and another another xor problem 题目链接:https://codeforces.com/contest/1088/problem/D Descripti ...

  6. cf1088D Ehab and another another xor problem (构造)

    题意:有两数a,b,每次你可以给定c,d询问a xor c和b xor d的大小关系,最多询问62次($a,b<=2^{30}$),问a和b 考虑从高位往低位做,正在做第i位,已经知道了a和b的 ...

  7. Codeforces Round #525 (Div. 2) D. Ehab and another another xor problem(交互题 异或)

    题目 题意: 0≤a,b<2^30, 最多猜62次. 交互题,题目设定好a,b的值,要你去猜.要你通过输入 c d : 如果 a^c < b^d ,会反馈 -1 : 如果 a^c = b^ ...

  8. Codeforces Round #563 (Div. 2) E. Ehab and the Expected GCD Problem

    https://codeforces.com/contest/1174/problem/E dp 好题 *(if 满足条件) 满足条件 *1 不满足条件 *0 ///这代码虽然写着方便,但是常数有点大 ...

  9. Codeforces Round #525 D - Ehab and another another xor problem /// 构造

    题目大意: 本题有两个隐藏起来的a b(1<=a,b<=1e30) 每次可 printf("? %d %d\n",c,d); 表示询问 a^c 与 b^d 的相对大小 ...

随机推荐

  1. Flask无法访问(127.0.0.1:5000)的问题解决方法

    Flask默认开启的ip地址是:http://127.0.0.1:5000/ 但在运行时可能存在无法访问的问题,特别是当我们在linux服务器上搭建flask时,此时需要将代码修改如下: app.ru ...

  2. 数据多的时候为什么要使用redis而不用mysql?

    2018-06-28  136465569...  转自 庆亮trj21bc... 修改   微信 分享: Redis和MySQL的应用场景是不同的. 通常来说,没有说用Redis就不用MySQL的这 ...

  3. python之统计字符串中字母出现次数

    dic=dict() d={} s=set() s='helloworld' (1)d=dict() for x in s: if x not in d.keys(): d[x]=1 else: d[ ...

  4. webpack资源加载常用配置

    const path = require('path'); module.exports = { entry: './src/index.js', output: { filename: 'bundl ...

  5. jQuery 事件介绍

    什么是事件?页面对不同访问者的响应叫做事件.事件处理程序指的是当 HTML 中发生某些事件时所调用的方法. 常用的时间主要有以下几种: click()事件:click() 方法是当按钮点击事件被触发时 ...

  6. EntityFramework进阶(一)- DbContext与ObjectContext互转

    本系列原创博客代码已在EntityFramework6.0.0测试通过,转载请标明出处 EF中我们常用的是DbContext作为上下文,如果要想获取元数据等信息还是要用到ObjectContext这个 ...

  7. [iOS]UIButton内、外边距设置

    - (void)viewDidLoad {        [super viewDidLoad];        /*         UIButton设置对应的边距image跟title的边距属性  ...

  8. Java 函数调用是传值还是传引用? 从字节码角度来看看!

    原文地址:点击打开

  9. [Python]pip install offline 如何离线pip安装包

    痛点:目标机器无法连接公网,但是能使用rz.sz传输文件 思路:在能上网的机器是使用pip下载相关依赖包,然后传输至目标机器,进行安装 0. Install pip: http://pip-cn.re ...

  10. G1垃圾收集器原理剖析【官方解读】

    继续基于上一次https://www.cnblogs.com/webor2006/p/11135005.html的官方G1文档进行解读,上一次分析到了这: 话不多说,继续往前读: When perfo ...