CF1174D Ehab and the Expected XOR Problem(二进制)
做法
求出答案序列的异或前缀和\(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(二进制)的更多相关文章
- CF1174D Ehab and the Expected XOR Problem
思路: 使用前缀和技巧进行问题转化:原数组的任意子串的异或值不能等于0或x,可以转化成前缀异或数组的任意两个元素的异或值不能等于0或x. 实现: #include <bits/stdc++.h& ...
- 【CF1174D】 Ehab and the Expected XOR Problem - 构造
题面 Given two integers \(n\) and \(x\), construct an array that satisfies the following conditions: · ...
- CF D. Ehab and the Expected XOR Problem 贪心+位运算
题中只有两个条件:任意区间异或值不等于0或m. 如果只考虑区间异或值不等于 0,则任意两个前缀异或值不能相等. 而除了不能相等之外,还需保证不能出现任意两个前缀异或值不等于m. 即 $xor[i]$^ ...
- codeforces#1157D. Ehab and the Expected XOR Problem(构造)
题目链接: http://codeforces.com/contest/1174/problem/D 题意: 构造一个序列,满足以下条件 他的所有子段的异或值不等于$x$ $1 \le a_i< ...
- 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 ...
- 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的 ...
- 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^ ...
- Codeforces Round #563 (Div. 2) E. Ehab and the Expected GCD Problem
https://codeforces.com/contest/1174/problem/E dp 好题 *(if 满足条件) 满足条件 *1 不满足条件 *0 ///这代码虽然写着方便,但是常数有点大 ...
- 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 的相对大小 ...
随机推荐
- English-培训1-Phonetic symbols
- python 3.6 + robotFramework自动化框架 环境搭建、学习笔记
################################################################# #author: 陈月白 #_blogs: http://www.c ...
- JAVA笔记整理(九),JAVA中的集合
在工作中,我们经常需要将多个对象集中存放,可以使用数组,但是数组的长度一旦固定之后是不可变的,为了保存数量确定的数据,我们可以使用JAVA中的集合. 在我看来,JAVA中的集合可以看作是一个特殊的数据 ...
- 记录java+testng运行selenium(三)---xml、ini、excel、日志等配置
一: ini文件 ini目前只用处存储浏览类型及需要打开的url,ini文件放在configs文件夹下面. 读取ini代码如下: package toolskit.documents; import ...
- iview DatePicker 只能选本月
html <FormItem label="活动时间" prop="activity_time"> <DatePicker v-model=& ...
- CaaSP4 - 命令记录
worker01:~ # tree /var/lib/containers/storage/ -L 1 /var/lib/containers/storage/ ├── mounts ├── over ...
- python小知识点汇总
一 写mysql 场景:自动化用例中需要构造数据,写入redis 表中已有该primary_key的记录,在现有基础上更新字段 表中无该记录,需要插入 # 请求传入table字段,db.table,c ...
- G1垃圾收集器设计目标与改良手段【纯理论】
在之前已经详细对CMS垃圾回收器进行了学习,今天准备要学习另一个全新的垃圾收集器---G1(Garbage First Collector 垃圾优先的收集器),说是一种全新的,其实G1垃圾收集器已经出 ...
- vue+webpack4 脚手架搭建
1, vue 中 h => h(App) 的含义: //render: h => h(App) 是下面内容的缩写: render: function (createElement) { r ...
- 判断变量是否不为空,函数isset()、!empty()与!is_null()的比较
转载:https://blog.csdn.net/qq_38812954/article/details/79581785 判断变量的值,尤其是判断他们是否不为空,我们有以下4种方法: if(isse ...