CF979D Kuro and GCD and XOR and SUM 题解
维护
查询
维护子树最小值,贪心进入某棵子树时判一下这个子树里有没有
#include <cstdio>
#include <algorithm>
using namespace std;
struct T
{
int v, c[2];
} R[30000050];
bool b[100050];
int n, o, p[100050];
void I(int x, int r)
{
R[r].v = min(R[r].v, x);
for (int i = 20, p = r; i >= 0; --i)
if (R[p].c[x >> i & 1])
p = R[p].c[x >> i & 1], R[p].v = min(R[p].v, x);
else
p = R[p].c[x >> i & 1] = ++o, R[p].v = x;
}
int Q(int x, int s, int r)
{
if (x + R[r].v > s)
return -1;
int q = 0, p = r;
for (int i = 20; i >= 0; --i)
if (R[p].c[~x >> i & 1] && x + R[R[p].c[~x >> i & 1]].v <= s)
p = R[p].c[~x >> i & 1];
else
p = R[p].c[x >> i & 1];
return R[p].v;
}
int main()
{
for (int i = 1; i <= 1e5; ++i)
R[p[i] = ++o].v = 1e9;
scanf("%d", &n);
for (int i = 0, o, x, k, s; i < n; ++i)
{
scanf("%d%d", &o, &x);
if (o & 1)
{
if (!b[x])
{
b[x] = 1;
for (int j = 1; j * j <= x; ++j)
if (!(x % j))
{
I(x, p[j]);
if (j * j != x)
I(x, p[x / j]);
}
}
}
else
scanf("%d%d", &k, &s), printf("%d\n", x % k ? -1 : Q(x, s, p[k]));
}
return 0;
}
分类:
题解
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具