[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. .Net面试题三

    1..Net中类和结构的区别? 2.死锁地必要条件?怎么克服? 3.接口是否可以继承接口?抽象类是否可以实现接口?抽象类是否可以继承实体类? 4.构造器COnstructor是否可以被继承?是否可以被 ...

  2. XML转换成DataTable

    #region XML转dataset //str 是xml字符串 public static DataTable GetResultXMLToDataTable (string str,string ...

  3. QByteArray详解

    QByteArray在串口通讯中经常被使用,有一定必要较为全面详细的对QByteArray进行阐述.本文通过以下几个部分加以介绍: 1. 初始化 2. 访问与赋值 3. 添加.删除.插入与替换操作 4 ...

  4. SNI功能在NetScaler上的实现

    SNI功能在NetScaler上的实现 来源  https://raynorli.com/2018/09/11/sni-on-netscaler/ 现网中经常是一台主机上运行多个Web站点,如果启用了 ...

  5. 异常-try...catch的方式处理异常2

    package cn.itcast_02; /* * A:一个异常 * B:二个异常的处理 * a:每一个写一个try...catch * b:写一个try,多个catch * try{ * ... ...

  6. Typora入门:全网最全教程

    目录 简介 Markdown介绍 常用快捷键 块元素 换行符 标题级别 引用文字 无序列表 有序列表 任务列表 代码块 数学表达式 插入表格 脚注 分割线 目录(TOC) 跨度元素 链接 网址 图片 ...

  7. S=a+aa+aaa...(js)

    /*求s=a+aa+aaa+aaaa+aa...a的值,其中a是一个数字. 例如2+22+222+2222+22222(此时共有5个数相加),几个数相加有键盘控制.*/ let readline = ...

  8. Delphi 使用数据库浏览器

    樊伟胜

  9. js excel导出功能

    <html> <head> <p style="font-size: 20px;color: red;">使用a标签方式将json导出csv文件 ...

  10. php的加解密openssl_encrypt与openssl_decrypt

    https://blog.csdn.net/zhemejinnameyuanxc/article/details/83383434   php的加解密