题意:

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

$(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. Android基础控件ImageView的使用

    1.相关属性 <!--src 设置内容--> <!--background 设置背景--> <!--alpha 设置透明度 --> <!--adjustVie ...

  2. PAT甲级——A1006 Sign In and Sign Out

    At the beginning of every day, the first person who signs in the computer room will unlock the door, ...

  3. java开发系列-Http协议

    概述 HTTP(HyperText Transfer Protocol)是互联网上应用最为广泛的一种网络协议.这种协议用来规定通信数据的格式. HTTP请求 浏览器往服务器发送数据称之为请求.HTTP ...

  4. Link-Cut Tree(LCT)

    转载自LCT(Link-Cut Tree)详解(蒟蒻自留地) 如果你还没有接触过LCT,你可以先看一看这里: (看不懂没关系,先留个大概的印像)http://www.cnblogs.com/BLADE ...

  5. mac上安装软件后,桌面上软件的图标如何去掉?

    桌面上的图标是软件的镜像包,默认安装以镜像形式,你选中它,按command+e 就可以推掉它

  6. gitlab merge request

    分支提了mr之后, 又有commit 不用重新提mr,mr中会自动更新 要保证项目下的.git目录中有hooks这个目录(如果是从github迁移到gitlab的项目, 可能没有这个目录, 导致mr不 ...

  7. Ajax的简单基础

    什么是 AJAX ? AJAX 是一种用于创建快速动态网页的技术. 通过在后台与服务器进行少量数据交换,AJAX 可以使网页实现异步更新. 这意味着可以在不重新加载整个网页的情况下,对网页的某部分进行 ...

  8. 简单易学的机器学习算法——基于密度的聚类算法DBSCAN

    一.基于密度的聚类算法的概述     最近在Science上的一篇基于密度的聚类算法<Clustering by fast search and find of density peaks> ...

  9. 创建 SSH Keys

    SSH 为 Secure Shell 的缩写,由 IETF 的网络小组(Network Working Group)所制定.利用 SSH 协议可以有效防止远程管理过程中的信息泄露问题.简单说,SSH是 ...

  10. Octave 软件的安装

    每次安装软件都感觉是一种心痛的历程.下载安装,然后就跳出一堆的错误,之后就各种百度求救,然后就搞了大半天,有时候还搞不定. 最后,搞定的时候发现,原来这么简单,结果时间就这样浪费了,所以还是把这个过程 ...