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 ...
随机推荐
- linux 后渗透测试
学习参考: http://weibo.com/1869235073/B9Seswf9R?type=comment http://weibo.com/p/1001603723521007220513 h ...
- 真实场景中WebRTC 用到的服务 STUN, TURN 和 signaling
FQ收录转自:WebRTC in the real world: STUN, TURN and signaling WebRTC enables peer to peer communication. ...
- POJ 3469 Dual Core CPU(最小割模型的建立)
分析: 这类问题的一遍描述,把一些对象分成两组,划分有一些代价,问最小代价.一般性的思路是, 把这两组看成是S点和T点,把划分的代价和割边的容量对应起来求最小割. 把S和可模版tem之间到达关系看作是 ...
- RHEL7 本地yum源配置
配置yum 源 1.挂载DVD光盘到/mnt 因为配置时候路径名里面不能有空格,否则不能识别 [root@ mnt]# mount /dev/cdrom /mnt 2.在目录/etc/yum.r ...
- java Socket 客户端服务端对接正确写法(BIO)
之前在工作中写过一些Socket客户端与服务端的代码,但是当时没有时间仔细研究,只能不报错先过的态度,对其细节了解不深,写的代码有各种问题也浑然不知,只是业务量级以及对接方对接代码没有出现出格的情况所 ...
- Python02 变量
变量 因为Python是弱变量类型编程语言,所以变量赋值不需要类型声明. 每个变量在内存中创建,都包括变量的标识,名称和数据这些信息. 每个变量在使用前都必须赋值,变量赋值以后该变量才会被创建. 变量 ...
- C# WinForm 绘制圆角窗体
public void SetWindowRegion() { System.Drawing.Drawing2D.GraphicsPath FormPath; FormPath = new Syste ...
- UsbKey开发
http://slf-1983.blog.163.com/blog/static/2990236320121113113955119/
- nodejs 爬虫
参考了各位大大的,然后自己写了个爬虫 用到的modules:utils.js --- moment module_url.js var http = require("http ...
- arr.forEach()与for...in的用法举例
1.forEach() 将给定的数字转换成罗马数字. 所有返回的 罗马数字 都应该是大写形式. function convert(num) { var str = ""; var ...