[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字典树)的更多相关文章

  1. 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( ...

  2. 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, ...

  3. codeforces 979D Kuro and GCD and XOR and SUM

    题意: 给出两种操作: 1.添加一个数字x到数组. 2.给出s,x,k,从数组中找出一个数v满足gcd(x,k) % v == 0 && x + v <= s && ...

  4. D. Kuro and GCD and XOR and SUM

    Kuro is currently playing an educational game about numbers. The game focuses on the greatest common ...

  5. 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 ...

  6. 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 ...

  7. 【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,并 ...

  8. cf979d Kuro and GCD and XOR and SUM

    set做法 正解是trie-- 主要是要学会 \(a\ \mathrm{xor}\ b \leq a+b\) 这种操作 #include <iostream> #include <c ...

  9. 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 ...

随机推荐

  1. centos 服务器 发开防火墙端口

    一.概述 在服务器上手动安装了某个软件,需要通过外部访问该软件(有对外开放端口),但是此时访问不通,此时检查,发现是该端口没有在防火墙开放,因此外界访问不了该服务器上的该软件对外提供的功能,基于此,需 ...

  2. ES6基础之——new Set

    Set 对象存储的值总是唯一的 Set 对象方法 方法 描述 add 添加某个值,返回Set对象本身. clear 删除所有的键/值对,没有返回值. delete 删除某个键,返回true.如果删除失 ...

  3. node 基本搭建 server.js

    const express = require('express'); const expressStatic = require('express-static'); const bodyparse ...

  4. 《python解释器源码剖析》第6章--python中的dict对象

    6.0 序 元素和元素之间可能存在着某种关系,比如学生姓名和成绩.我希望能够通过学生的姓名找到这个学生的成绩,那么只需要将两者关联起来即可.字典正是这么做的,字典中的每个元素就是一个key:value ...

  5. PhotoShop更改图片背景色

    PhotoShop更改图片背景色 操作步骤如下所示: 打开图片==>图像/调整/替换颜色==>选择颜色==>选择油漆桶工具==>点击需要被替换的图片背景色 注:不知道什么原因 ...

  6. 关于C语言打印string类字符串的问题

    首先因为printf函数输出字符串是针对char *的,即printf只能输出c语言的内置数据,而string不是c语言的内置数据. 其次string类型的对象不止包含字符串,还包含了许多用于操作的函 ...

  7. BaseAdapter的使用与优化

    1.逗比式 //逗比式............................................ //加载布局文件 //将xml文件转化为view,获取到view//由于我们只需要将XM ...

  8. linux获取某一个网卡的ipv4地址

    ip a show ens33 | grep inet | grep -v inet6 | awk '{print $2}' | awk -F '/' '{print $1}'

  9. Python中json的简单读写操作

    Python中json的简单读写操作 JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于ECMAScript的一个子集. JSON采用完全独立于语言的 ...

  10. 异步IO框架:asyncio 中篇

    上一节我们首先介绍了,如何创建一个协程对象.主要有两种方法 通过async关键字, 通过@asyncio.coroutine 装饰函数. 然后有了协程对象,就需要一个事件循环容器来运行我们的协程.其主 ...