D. Kuro and GCD and XOR and SUM 字典树真好玩... 牛老板提供的思路:建1e5个 字典树,每个数插入到以它的因子为根所在的字典树中,这样就实现了整除,当然gcd(k, x) = k是必须的 然后如何保证v + x <= s 和 v ^ x 最大呢? 对于v + x <= s,我们可以维护01字典树中,经过每个节点的最小值,这样我们在访问每个节点时,直接min + x <= s 判断是否成立即可, 不成立就不用往下走了,因为最小值都不成立. 对于v ^ x最…
Codeforces 979 D. Kuro and GCD and XOR and SUM 题目大意:有两种操作:①给一个数v,加入数组a中②给出三个数x,k,s:从当前数组a中找出一个数u满足 u与x的gcd可以被k整除,u不大于s-x,且与x的异或和最大. 思路:之前没有碰到过异或和最值的问题,所以是懵逼的.学习了01字典树后把这题补出来. 碰到操作①就上树,上树过程中注意不断维护每个节点往后路径中的最小值(具体见代码细节): 碰到操作②,如果k==1,那么从树上找数的同时注意限制条件最小…
Kuro and GCD and XOR and SUM 题意:给你一个空数组. 然后有2个操作, 1是往这个数组里面插入某个值, 2.给你一个x, k, s.要求在数组中找到一个v,使得k|gcd(x,v) (即gcd(x,v)是k的倍数,v+x <= k, x ^ v的值最大. 题解:XOR亦或问题是经典的题目,一般都是用01字典树去处理. 然后需要满足条件1, 所以我们可以对于每一个点建立一个字典树,每次添加数的时候都往这个数的因子添加这个值,这样我们直接访问对应的k就可以找到答案了.…
CF 979D Kuro and GCD and XOR and SUM(异或 Trie) 给出q(<=1e5)个操作.操作分两种,一种是插入一个数u(<=1e5),另一种是给出三个数x,k,s(<=1e5),求当前所有u中满足,k|u,x+u<=s,且\(x\oplus u\)最大的u. 做法好神啊.关于异或的问题有一种常见做法,就是利用01trie来查找在一堆数里面,哪个数与x的异或值最大.这道题就是这个思路.如果去掉k必须整除v这个条件,那么就转化成了上一个问题(只不过有最大…
地址:http://codeforces.com/contest/766/problem/E 题目: E. Mahmoud and a xor trip time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mahmoud and Ehab live in a country with n cities numbered from …
Kuro is currently playing an educational game about numbers. The game focuses on the greatest common divisor (GCD), the XOR value, and the sum of two numbers. Kuro loves the game so much that he solves levels by levels day by day. Sadly, he's going o…
Kuro is currently playing an educational game about numbers. The game focuses on the greatest common divisor (GCD), the XOR value, and the sum of two numbers. Kuro loves the game so much that he solves levels by levels day by day. Sadly, he's going o…