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 ...
随机推荐
- ELF interpreter /libexec/ld-elf32.so.1 not found
ELF interpreter /libexec/ld-elf32.so.1 not found错误, 其实就是在64位平台上运行32位软件的不兼容造成的.找个64的包安装就上ok了.
- 利用expect实现自动化操作
管理机上需要安装expect包 yum -y install expect 1.定义主机ip [root@localhost ~]# cat ip.txt 192.168.1.12 192.168.1 ...
- ASP.NET的三种开发模式
前言 ASP.NET 是一个免费的Web开发框架,是由微软在.NET Framework框架中所提供的,或者说ASP.NET是开发Web应用程序的类库,封装在System.Web.dll 文件中.AS ...
- c++ STL deque容器成员函数
deque是双向队列,即可以在头部插入删除,也可以在尾部插入删除.内部并不连续,这一点和vector并不一样.可能第1个元素和第2个元素的地址是不连在一起的.在使用时用it迭代器会安全一点. 这是c+ ...
- HDU 3351 Seinfeld 宋飞正传(水)
题意: 给出一个串,串内只有大括号,问经过几次改变可使全部括号合法?改变指的是可以将某一方向的括号变成另一方向. 思路: 利用栈的特点,若出现成对的合法括号,直接删掉,留下那些不合法的成为一串.既然不 ...
- Metasploitable渗透测试实战——Windows漏洞 MS08-067复现
Ms08-067 攻防环境: 攻击机:kali ip:198.168.12.212 靶机:Window XP 未打过ms08-067补丁 ip:198.168.12.209
- hihocoder 1093 SPFA算法
题目链接:http://hihocoder.com/problemset/problem/1093 , 最短路的SPFA算法. 由于点的限制(10w),只能用邻接表.今天也学了一种邻接表的写法,感觉挺 ...
- 部署git服务器(Windows Server 2008)
原来的这个项目是一个人开发的,没有做版本管理,我接手后准备搭建git版本管理服务端,方便离线开发和做版本管理: 一台云主机,操作系统:Windows Server 2008,64位: java已经安装 ...
- IOS 绘制基本图形(画文字、图片水印)
- (void)drawRect:(CGRect)rect { // Drawing code // [self test]; // 1.加载图片到内存中 UIImage *image = [UIIm ...
- IOS UIButton常用属性
//1.添加按钮 UIButton *nameView=[UIButton buttonWithType:UIButtonTypeCustom]; //nameView.backgroundColor ...