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 的相对大小 ...
随机推荐
- C#从零单排上王者系列---数据类型
从零单排系列简介 突然发现自己的基础不是很牢固,就买了一个<C#7.0的本质论>.本系列博客就是以此书为本,记录自己的学习心得,如果你的基础也不牢固,不如跟上博主一起学习成长呀! 本篇博客 ...
- winfrom 集成krpano 项目 添加折线
C#.NET WinFrom开发之嵌入Google浏览器 (CefSharp) 引入静态页面 CefWebBrowser = new ChromiumWebBrowser("http://& ...
- vue+iview的form表单校验总结
这篇文章时关于如何使用iview的form表单校验.主要学习如何使用form校验(以校验文字长度为例),以及如何动态添加校验规则和异步校验. 1.为需要校验的表单添加form标签 <!--注意: ...
- 90% 的 Python 开发者不知道的描述符应用
经过上面的讲解,我们已经知道如何定义描述符,且明白了描述符是如何工作的. 正常人所见过的描述符的用法就是上篇文章提到的那些,我想说的是那只是描述符协议最常见的应用之一,或许你还不知道,其实有很多 Py ...
- ubuntu16.04环境下在docker上部署javaweb项目简单案例
因为一些原因,接触到了docker,经过一番研究,总算是有了一些自己的看法,有什么不对的地方,希望多多指教. 废话不多说,首先我这里使用的虚拟机安装的是ubuntu16.04版本,其他版本应该也可以. ...
- mybatisplus 使用案例
案例地址 https://github.com/qixianchuan/SpringBootQD/tree/master/mybatisplus
- SEO运用meta标签进行网站优化
SEO定义 Search Engine Optimization 搜索引擎优化 一,常用的HTTP-EQUIV类型: Set-Cookie(cookie设定) 说明:如果网页过期,存盘的cookie将 ...
- aspx反射调用方法
string name = base.Request["action"]; ]); if (obj2 != null) { s = obj2.ToString(); } 传入方法名 ...
- Django之小结
常用的函数方法与包的调用 # 登陆视图函数 def login(request): if request.method == 'GET': return render(request,'login.h ...
- 在Linux中安装ASPNET.Core3.0运行时
# 以下示例适用于x64位runtime v3.0.0 mkdir /runtimes cd /runtimes wget https://download.visualstudio.microsof ...