题意:

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

$(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. iOS之CGcontext.h方法和属性简介

    /* CoreGraphics - CGContext.h Copyright (c) 2000-2012 Apple Inc. All rights reserved. */ #ifndef CGC ...

  2. 机器学习(二)数据处理&相似/异性度量

    机器学习(二)数据处理&相似/异性度量 https://woaielf.github.io/2017/03/17/dm-2/ 2017-03-17 ZOE    数据科学  机器学习/数据挖掘 ...

  3. JS对象迭代v-for

    <!DOCTYPE html> <html lang="zh"> <head> <title></title> < ...

  4. OpenCASCADE圆与平面求交

    OpenCASCADE圆与平面求交 eryar@163.com 在 解析几何求交之圆与二次曲面中分析了OpenCASCADE提供的类IntAna_IntConicQuad可以用来计算圆与二次曲面之间的 ...

  5. PAT甲级——A1084 Broken Keyboard

    On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters ...

  6. Django自带的认证系统

    Django自带的用户认证 我们在开发一个网站的时候,无可避免的需要设计实现网站的用户系统.此时我们需要实现包括用户注册.用户登录.用户认证.注销.修改密码等功能,这还真是个麻烦的事情呢. Djang ...

  7. sql草稿

    参考:MySQL 内连接.外连接.左连接.右连接.全连接 SELECT count(*) FROM `t_product_base` select m_name from t_medicinal_in ...

  8. python内置类型详细解释

    文章编写借鉴于内置类型 - Python 3.7.3 文档,主要用于自己学习和记录 python主要内置类型包括数字.序列.映射.类.实例和异常 有些多项集类是可变的.它们用于添加.移除或重排其成员的 ...

  9. csp-s模拟测试51(b)attack,tree题解

    题面:https://www.cnblogs.com/Juve/articles/11598286.html attack: 支配树裸题? 看一下支配树是什么: 问题:我们有一个有向图(可以有环),定 ...

  10. HZOI20190902模拟35题解

    题面: A:公园 DAG上想拓扑dp 然而博主记忆化搜索了一下 设f[i][j]表示从i节点走j个点出公园所用的最小时间 则$f[u][i]=min(f[v][j-1]+dis_{u,v})$; 然后 ...