Codeforces 979 D. Kuro and GCD and XOR and SUM(异或和,01字典树)
[Codeforces 979 D. Kuro and GCD and XOR and SUM](http://codeforces.com/problemset/problem/979/D)
题目大意:有两种操作:①给一个数v,加入数组a中②给出三个数x,k,s;从当前数组a中找出一个数u满足 u与x的gcd可以被k整除,u不大于s-x,且与x的异或和最大。
思路:之前没有碰到过异或和最值的问题,所以是懵逼的。学习了01字典树后把这题补出来。
碰到操作①就上树,上树过程中注意不断维护每个节点往后路径中的最小值(具体见代码细节);
碰到操作②,如果k==1,那么从树上找数的同时注意限制条件最小值不超过s-x;如果k>1,那么直接枚举找最值。
```C++
#include
#include
#include
#include
#include
#include
using namespace std;
const int maxn=1e5+10;
bool a[maxn];
struct Trie_01
{
static const int N = 32*maxn , M = 2;
int node[N][M],value[N],rt,L;
void init()
{
fill_n(node[N-1],M,0);
fill_n(value,N,INT_MAX);
L = 0;
rt = newnode();
}
int newnode()
{
fill_n(node[L],M,0);
return L++;
}
void add(int x)
{
int p = rt;
value[p]=min(value[p],x);
for (int i=31;i>=0;--i)
{
int idx = (x>>i)&1;
if (!node[p][idx])
{
node[p][idx] = newnode();
}
p = node[p][idx];
value[p]=min(value[p],x);
}
}
int query(int x,int bound)
{
int p = rt;
if (value[p]>bound)
return -1;
for (int i=31;i>=0;--i)
{
int idx = (x>>i)&1;
if (node[p][idx^1]&&value[node[p][idx^1]]>n;
tree.init();
for (i=0;imx)
{
mx=j^x;
ans=j;
}
}
cout
Codeforces 979 D. Kuro and GCD and XOR and SUM(异或和,01字典树)的更多相关文章
- CodeForces 979 D Kuro and GCD and XOR and SUM
Kuro and GCD and XOR and SUM 题意:给你一个空数组. 然后有2个操作, 1是往这个数组里面插入某个值, 2.给你一个x, k, s.要求在数组中找到一个v,使得k|gcd( ...
- CF 979D Kuro and GCD and XOR and SUM(异或 Trie)
CF 979D Kuro and GCD and XOR and SUM(异或 Trie) 给出q(<=1e5)个操作.操作分两种,一种是插入一个数u(<=1e5),另一种是给出三个数x, ...
- codeforces 979D Kuro and GCD and XOR and SUM
题意: 给出两种操作: 1.添加一个数字x到数组. 2.给出s,x,k,从数组中找出一个数v满足gcd(x,k) % v == 0 && x + v <= s && ...
- D. Kuro and GCD and XOR and SUM
Kuro is currently playing an educational game about numbers. The game focuses on the greatest common ...
- CodeForces979D:Kuro and GCD and XOR and SUM(Trie树&指针&Xor)
Kuro is currently playing an educational game about numbers. The game focuses on the greatest common ...
- Codeforces Round #482 (Div. 2) : Kuro and GCD and XOR and SUM (寻找最大异或值)
题目链接:http://codeforces.com/contest/979/problem/D 参考大神博客:https://www.cnblogs.com/kickit/p/9046953.htm ...
- 【Trie】【枚举约数】Codeforces Round #482 (Div. 2) D. Kuro and GCD and XOR and SUM
题意: 给你一个空的可重集,支持以下操作: 向其中塞进一个数x(不超过100000), 询问(x,K,s):如果K不能整除x,直接输出-1.否则,问你可重集中所有是K的倍数的数之中,小于等于s-x,并 ...
- cf979d Kuro and GCD and XOR and SUM
set做法 正解是trie-- 主要是要学会 \(a\ \mathrm{xor}\ b \leq a+b\) 这种操作 #include <iostream> #include <c ...
- cf round 482D Kuro and GCD and XOR and SUM
题意: 开始有个空集合,现在有两种操作: $(1,x)$:给集合加一个数$x$,$x \leq 10^5$; $(2,x,k,s)$:在集合中找一个$a$,满足$a \leq s-x$,而且$k|gc ...
随机推荐
- 怎样理解 Vue 项目的目录结构?
Vue 项目的目录结构如下, 我们将会在后面逐个去了解它们的作用: 01. build - 存储项目构建相关的代码, 比如 webpack. 02. config - Vue 的配置目录,包括端口 ...
- 19-Perl 特殊变量
1.Perl 特殊变量Perl 语言中定义了一些特殊的变量,通常以 $, @, 或 % 作为前缀,例如:$_.很多特殊的变量有一个很长的英文名,操作系统变量 $! 可以写为 $OS_ERROR.如果你 ...
- Redis基本数据
Redis Redis是一个速度非常快的非关系数据库(NoSql),它可以存储键(key)与五种不同的值(value)之间的映射.可以将存储的内存的键值对数据持久化到硬盘. Redis 数据结构 Re ...
- c# 后台隐式使用webBrowser
c#不使用 webBrowser 控件, 在后台加载html流 private void button1_Click(object sender, EventArgs e) { string urlP ...
- Eclipse 快捷键、文档注释、多行注释的快捷键
关于快捷键 Eclipse 的很多操作都提供了快捷键功能,我们可以通过键盘就能很好的控制 Eclipse 各个功能: 一.多行注释快捷键 1.选中你要加注释的区域,用ctrl+shift+C 或者ct ...
- 完美解决Uncaught SyntaxError: Unexpected end of input
Unexpected end of input 的英文意思是“意外的终止输入” 他通常表示我们浏览器在读取我们的js代码时,碰到了不可预知的错误,导致浏览器 无语进行下面的读取 通常造成这种错误的原 ...
- linux常用命令(4)
linux常用命令(4) --- Vim编辑器与Shell命令脚本 如何使用vim编辑器来编写文档.配置主机名称.网卡参数以及yum仓库: 通过vim编辑器将Linux命令放入合适的逻辑测试语句(if ...
- CDH6.1.0新增主机资源
在CDH 6.1.0 上增加主机 一 客户端配置 1.1 JAVA 配置 1.2 关闭selinux以及防火墙 1.3 将服务端的agent包打包然后拷贝到客户端 然后解压 启动(也可以rpm安装) ...
- ado.net 断开 非断开
非断开 SqlConnection SqlCommand / SqlDataReader 接 断开 SqlConnection SqlDataAdapter / DataSet 接
- 【异常】Caused by: java.lang.IllegalStateException: Zip64 archives are not supported
1 自己打包Spring boot项目依赖了第三方的Phoenix jar包过大,导致启动后报错 参考了这篇博客:https://cloud.tencent.com/developer/ask/135 ...