CF1446C Xor Tree
1.[博客迁移20190713]题解 P4169 【[Violet]天使玩偶/SJY摆棋子】2.模拟题3.SP666 VOCV - Con-Junctions 题解4.Codeforces Round #900 (Div. 3)5.Codeforces Round 962 (Div. 3)6.题解 CF993E 【Nikita and Order Statistics】7.题解 P6891 【[JOISC2020]ビルの飾り付け 4】8.P2163 [SHOI2007] 园丁的烦恼9.[POI2011] LIZ-Lollipop10.Codeforces Round 973 (Div. 2)11.Codeforces Round 974 (Div. 3)12.NEERC2013题解
13.CF1446C Xor Tree
14.Codeforces Round 709 (Div. 1)15.Codeforces Round 975 (Div. 2)16.NEERC2014题解17.题解 P2726 【[SHOI2005]树的双中心】18.CF2019 F. Max Plus Min Plus Size19.Codeforces Round 757 (Div. 2)很有意思的题目,我们考虑能连边的两个数一定是在 01-Trie 上距离最近的两个点。于是我们先把所有数插入到 01-Trie 上去,然后
const int M = 30;
const int N = 2e5 + 5;
int n, a[N];
struct Trie {
int t[N * M][2], ed[N * M], dp[N * M], tot;
inline void clear(void) {
for (int i = 0; i <= tot; i++) t[i][0] = t[i][1] = ed[i] = dp[i] = 0;
tot = 0;
}
Trie(void) { clear(); }
inline void insert(int val) {
int pos = 0;
for (int i = M; i >= 0; i--) {
int b = val >> i & 1;
if (!t[pos][b]) t[pos][b] = ++tot;
pos = t[pos][b];
}
ed[pos]++;
}
inline void remove(int val) {
int pos = 0;
for (int i = M; i >= 0; i--) {
int b = val >> i & 1;
if (!t[pos][b]) break;
pos = t[pos][b];
}
if (ed[pos]) ed[pos]--;
}
inline int query_min(int val) {
int pos = 0, ret = 0;
for (int i = M; i >= 0; i--) {
int b = val >> i & 1;
if (t[pos][b]) pos = t[pos][b];
else if (t[pos][1 - b]) ret = ret | (1 << i), pos = t[pos][1 - b];
else break;
} return ret;
}
inline int query_max(int val) {
int pos = 0, ret = 0;
for (int i = M; i >= 0; i--) {
int b = val >> i & 1; b = 1 - b;
if (t[pos][b]) pos = t[pos][b];
else if (t[pos][1 - b]) ret = ret | (1 << i), pos = t[pos][1 - b];
else break;
} return ret;
}
inline void dfs(int pos) {
int l = t[pos][0], r = t[pos][1];
if (l) dfs(l), chkmax(dp[pos], dp[l]);
if (r) dfs(r), chkmax(dp[pos], dp[r]);
if (l && r) dp[pos]++;
if (ed[pos]) dp[pos] = 1;
}
} T;
signed main(void) {
read(n);
for (int i = 1; i <= n; i++) read(a[i]), T.insert(a[i]);
T.dfs(0); writeln(n - T.dp[1]);
//fwrite(pf, 1, o1 - pf, stdout);
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下