cf979d Kuro and GCD and XOR and SUM
set做法
正解是trie……
主要是要学会 \(a\ \mathrm{xor}\ b \leq a+b\) 这种操作
#include <iostream>
#include <cstdio>
#include <set>
using namespace std;
int q, opt, uu, vv, ww;
set<int> se[100005];
int main(){
cin>>q;
while(q--){
scanf("%d", &opt);
if(opt==1){
scanf("%d", &uu);
for(int i=1; i*i<=uu; i++)
if(uu%i==0){
se[i].insert(uu);
se[uu/i].insert(uu);
}
}
else{
scanf("%d %d %d", &uu, &vv, &ww);
//x, k, s
if(uu%vv){
printf("-1\n");
continue;
}
set<int>::iterator it=se[vv].upper_bound(ww-uu);
if(se[vv].empty() || it==se[vv].begin()){
printf("-1\n");
continue;
}
it--;
int sum=-1, ans=-1;
for(; it!=se[vv].begin(); it--){
if(sum>(*it)+uu) break;
if(sum<((*it)^uu)){
sum = (*it) ^ uu;
ans = *it;
}
}
if(sum<((*it)^uu)){
sum = (*it) ^ uu;
ans = *it;
}
printf("%d\n", ans);
}
}
return 0;
}
cf979d Kuro and GCD and XOR and SUM的更多相关文章
- 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 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( ...
- Codeforces 979 D. Kuro and GCD and XOR and SUM(异或和,01字典树)
Codeforces 979 D. Kuro and GCD and XOR and SUM 题目大意:有两种操作:①给一个数v,加入数组a中②给出三个数x,k,s:从当前数组a中找出一个数u满足 u ...
- 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 979D Kuro and GCD and XOR and SUM
题意: 给出两种操作: 1.添加一个数字x到数组. 2.给出s,x,k,从数组中找出一个数v满足gcd(x,k) % v == 0 && x + v <= s && ...
- 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,并 ...
- 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 ...
随机推荐
- Today is the first day of the rest of your life.
Today is the first day of the rest of your life. 今天是你余下人生的第一天.
- CAS登录认证的简单介绍
参考博客: https://www.jianshu.com/p/8daeb20abb84 下面是CAS最基本的协议过程: 下面是CAS Web工作流程图: 名词解释 Ticket Grangting ...
- LAMP Stack 5.7.16 (Ubuntu 16.04.1)
平台: Ubuntu 类型: 虚拟机镜像 软件包: apache2.4 mysql5.7 php7 phpmyadmin4.5 apache application server basic soft ...
- 实战:ADFS3.0单点登录系列-ADFS3.0安装配置
本文为系列第三章,主要讲下ADFS3.0的安装和配置.本文和前面的文章是一个系列,因此有些地方是有前后关联,比如本文中使用的通配符证书就是第二篇讲解的,因此需要连贯的进行阅读. 全文目录如下: 实战: ...
- Sentinel spring-cloud-gateway adapter(1.6)异常错误之@EnableCircuitBreaker
sentinal 大坑 使用gateway adaper包出现@EnableCircuitBreaker did you forget include starter的异常 这时候千万不要学我引入cl ...
- [solr 管理界面] - 索引数据删除
删除solr索引数据,使用XML有两种写法: 1) <delete><id>1</id></delete> <commit/> 2) < ...
- Python02 变量
变量 因为Python是弱变量类型编程语言,所以变量赋值不需要类型声明. 每个变量在内存中创建,都包括变量的标识,名称和数据这些信息. 每个变量在使用前都必须赋值,变量赋值以后该变量才会被创建. 变量 ...
- cout对象一些常用方法的总结
cout.precision(n); 这个方法的功能是,设置精度为n,返还值是上一次的设置精度. #include <iostream> using namespace std; int ...
- 20180909 解析JS Cookie的设置,获取和检索
引用: JavaScript Cookie - by runoob.com Cookie是储存在电脑文本文件中的数据,用于保存访问者的信息,并可以在下次打开页面时引用. 页面在设置/引用访问者信息时, ...
- jsp页面:一个form,不同请求提交form
需求:一个表单中有一个请求 action="url"发送数据地址: 在表单外有一个请求,请求form表单提交的数据 我们用js来写:通过每次请求传不同的action=url; 例如 ...