题意:

开始有个空集合,现在有两种操作:

$(1,x)$:给集合加一个数$x$,$x \leq 10^5$;

$(2,x,k,s)$:在集合中找一个$a$,满足$a \leq s-x$,而且$k|gcd(a,x)$;现在需要找满足条件的$a$,它异或$x$的值最大。$x,k,s \leq 10^5$

操作数$q \leq 10^5$

这道题就是看你想到一个算法有没有去算算实际复杂度

我们发现,对于所有在$[1,10^5]$的$i$,$10^5$之内的$i$的倍数的个数和,并不是很大,只有$2*10^7$左右

然后就维护$10^5$个trie就好了……

//Serene
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;
#define ll long long
#define db double
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
const int maxn=2e5+7,maxm=2e7+7,W=1e5,U=16,INF=0x3f3f3f3f;
int n,root[maxn],tot=W;
int son[maxm][2],minnum[maxm];
bool vis[maxn]; char cc; ll ff;
template<typename T>void read(T& aa) {
aa=0;cc=getchar();ff=1;
while((cc<'0'||cc>'9')&&cc!='-') cc=getchar();
if(cc=='-') ff=-1,cc=getchar();
while(cc>='0'&&cc<='9') aa=aa*10+cc-'0',cc=getchar();
aa*=ff;
} int prime[maxn],totp,num[maxn];
bool ok[maxn];
void get_p() {
For(i,2,W) {
if(!ok[i]) prime[++totp]=i,num[i]=i;
For(j,1,totp) {
if(prime[j]>W/i) break;
ok[i*prime[j]]=1;
num[i*prime[j]]=prime[j];
if(i%prime[j]==0) break;
}
}
} void add(int pos,int x) {
minnum[pos]=min(minnum[pos],x);
int r;
Rep(i,U,0) {
r=(x>>i)&1;
if(!son[pos][r]) minnum[son[pos][r]=++tot]=x;
pos=son[pos][r]; minnum[pos]=min(minnum[pos],x);
}
} int zz[maxn];
void get_add(int x) {
if(vis[x]) return; vis[x]=1;
int s=1,t=1,p,now,y,o=x; zz[1]=1;
while(x!=1) {
p=num[x]; now=0; y=1;
while(x%p==0) x/=p,now++;
For(i,1,now) {
y*=p;
For(j,1,s) zz[++t]=zz[j]*y;
}
s=t;
}
For(i,1,t) add(zz[i],o);
} int get_ans(int x,int pos,int v) {
if(x%pos||minnum[pos]>v) return -1;
int r;
Rep(i,U,0) {
r=(x>>i)&1;
if(minnum[son[pos][r^1]]<=v) pos=son[pos][r^1];
else pos=son[pos][r];
}
return minnum[pos];
} int main() {
read(n); int op,k,x,v;
get_p();
For(i,0,W) minnum[i]=INF;
For(i,1,n) {
read(op); read(x);
if(op==1) get_add(x);
else {
read(k); read(v);
printf("%d\n",get_ans(x,k,v-x));
}
}
return 0;
}

  

cf round 482D 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 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 ...

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

  8. codeforces 979D Kuro and GCD and XOR and SUM

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

  9. cf979d Kuro and GCD and XOR and SUM

    set做法 正解是trie-- 主要是要学会 \(a\ \mathrm{xor}\ b \leq a+b\) 这种操作 #include <iostream> #include <c ...

随机推荐

  1. Linux 的文件和目录管理类命令

    文件和目录管理类的命令 目录: cd ~[username] ~:指定用户的家目录 cd -:回到上一次所在的目录 路径: 相对路径中: .:当前目录 ..:父目录 pwd: print workin ...

  2. day 36 MySQL的库、表的详细操作

    MySQL的库.表的详细操作   MySQL数据库 本节目录 一 库操作 二 表操作 三 行操作 一 库操作 1.创建数据库 1.1 语法 CREATE DATABASE 数据库名 charset u ...

  3. vue后台管理项目中菜单栏切换的三种方法

    第一种方法:vue嵌套路由(二) <el-menu :default-active="defaultActive" style="min-height: 100%; ...

  4. elasticsearch 中文API(一)

    Java API 这节会介绍elasticsearch支持的Java API.所有的elasticsearch操作都使用Client对象执行.本质上,所有的操作都是并行执行的. 另外,Client中的 ...

  5. 打开springboot的run dashboard

    默认情况下,idea的run dashboard是关闭的,当检测到你有多个springboot项目时会弹出提示框,询问是否打开. 如果我们想要自己打开,需要修改配置. 在你的idea的项目目录中,有一 ...

  6. 廖雪峰Java11多线程编程-1线程的概念-5中断线程

    1.中断线程: 如果线程需要执行一个长时间任务,就可能需要中断线程.场景:从网络上下载一个100M的文件,用户在下载过程中中断下载任务的执行. 中断线程就是其他线程给该线程发一个信号,该线程收到信号后 ...

  7. day72作业

    目录 models模型类 路由配置 视图配置 序列化组件配置 基于ModelSerializer类,完成Car资源的单查,群查,单增接口 序列化:显示车名,车的颜色,车的价格,车的海报,车的品牌 反序 ...

  8. linear-gradient

    http://jsbin.com/mocojehosa/edit?html,css,output https://developer.mozilla.org/zh-CN/docs/Web/CSS/li ...

  9. SpringData初探

    前言 项目中用到这个,没有学过,手动搭建,测试执行流程, 理论的东西有时间再补充 Maven依赖 <?xml version="1.0" encoding="UTF ...

  10. java基础之自定义单链表练习

    一.单链表 1.单链表是一种链式存取的数据结构,用一组地址任意的存储单元存放线性表中的数据元素.链表中的数据是以结点来表示的,每个结点的构成:元素(数据元素的映象) + 指针(指示后继元素存储位置), ...