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的更多相关文章

  1. 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, ...

  2. 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( ...

  3. 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 ...

  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 979D Kuro and GCD and XOR and SUM

    题意: 给出两种操作: 1.添加一个数字x到数组. 2.给出s,x,k,从数组中找出一个数v满足gcd(x,k) % v == 0 && x + v <= s && ...

  7. 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 ...

  8. 【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,并 ...

  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. maven validator数据校验

    1.maven文件中添加依赖包 <!-- validator校验--> <dependency> <groupId>org.hibernate</groupI ...

  2. 【Python】python2 str 编码检测

    python2 str 编码检测 import chardet s = 'sdffdfd' print type(s) print chardet.detect(s) s2 = '反反复复' prin ...

  3. 本地eclipse启动tomcat后无法访问

    转自博文:http://blog.csdn.net/wqjsir/article/details/7169838/ 症状: tomcat在eclipse里面能正常启动,而在浏览器中访问http://l ...

  4. LeetCode Implement strStr() 实现strstr()

    如题 思路:暴力就行了.1ms的暴力!!!别的牛人写出来的,我学而抄之~ int strStr(char* haystack, char* needle) { ; ; ; ++i) { ; ; ++j ...

  5. Producer & Consumer

    需要与Eureka结合使用 Eureka环境搭建 Producer 一.pom文件 <?xml version="1.0" encoding="UTF-8" ...

  6. iOS 7系列译文:认识 TextKit

    OS 7:终于来了,TextKit.   功能   所以咱们到了.iOS7 带着 TextKit 登陆了.咱们看看它可以做什么!深入之前,我还想提一下,严格来说,这些事情中的大部分以前都可以做.如果你 ...

  7. 【洛谷3759】[TJOI2017] 不勤劳的图书管理员(树套树)

    点此看题面 大致题意: 给定一个序列,每个元素有两个属性\(a_i\)和\(v_i\),每次操作改变两个元素的位置,求每次操作后\(\sum{v_i+v_j}[i<j,a_i>a_j]\) ...

  8. SpringMVC+Hibernate框架快速搭建

    1.  新建Maven项目springmvc 2.   pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" ...

  9. PostgreSql的使用

    title: PostgreSql的使用 tags: PostgreSql --- PostgreSql官网: https://www.postgresql.org/ 1 PostgreSql的安装 ...

  10. 毛毛虫组【Beta】Scrum Meeting 2

    第二天 日期:2019/6/24 前言 第二次会议: 时间:6月24日 地点:教10-503 内容:此次会议主要是进一步完善系统,分配进行文档的准备工作. 1.1 今日完成任务情况以及遇到的问题. 今 ...