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 ...
随机推荐
- 解决MyEclipse发布按钮无效的办法
删除Workspaces目录(存放您MyEclipse项目的地方)下的 “/.metadata/.plugins/org.eclipse.core.runtime/.settings/com.genu ...
- 管家婆crm9.2 sp2升级问题求助及解决方案
升级过程中发生如下问题: 弹出对话框1:升级完成,但是有错误产生. 弹出对话框2:升级数据库发生错误:An attempt was made to load an assembly from a ne ...
- Left4Dead2 LAN Online
Left4Dead2 LAN Online Franklin vs Wolverine 求生之路 局域网联机说明 ============================ 局域网联机方法: 1.先找到 ...
- [git] Updates were rejected because the tip of your current branch is behind its remote counterpart.
场景 $ git push To https://github.com/XXX/XXX ! [rejected] dev -> dev (non-fast-forward) error: fai ...
- C99 inline关键字
C99 inline 一直以来都用C++用得比较多,这个学期做操作系统的课设用回了C,结果一波內联函数居然链接不过去--查了查资料,C99引入的inline和C++的inline语义区别是很大的,我算 ...
- element ui input框不能输入的问题(实时学习)
解决: 在input的上面添加数据v-model 既可以 1.菜单中api (2018年8月14号) :default-active 默认根据当前路由选中菜单,值需要和 el-submenu 的属 ...
- java三大框架——Struts + Hibernate + Spring
Struts主要负责表示层的显示 Spring利用它的IOC和AOP来处理控制业务(负责对数据库的操作) Hibernate主要是数据持久化到数据库 再用jsp的servlet做网页开发的时候有个 w ...
- 深入分析 Docker 镜像原理
摘要:近日, DaoCloud 软件工程师孙宏亮在 CSDN Container 微信群为大家带来了 Docker 镜像原理的深度分享,本次分享的重点是 Docker 镜像,分享的内容主要包含两个部分 ...
- BZOJ 最大公约数 (通俗易懂&效率高&欧拉函数)
题目 题目描述 给定整数\(N\),求\(1 \le x,y \le N\)且\(gcd(x,y)\)为素数的数对\((x,y)\)有多少对. \(gcd(x,y)\)即求\(x,y\)的最大公约数. ...
- SAP导出内表数据到excel
DATA: EXCEL TYPE OLE2_OBJECT, SHEET TYPE OLE2_OBJECT, CELL TYPE OLE2_OBJECT, ...