[HDU]6059 Kanade's trio
来源:互联网 发布:js eval 编辑:程序博客网 时间:2024/06/16 05:52
URL : http://acm.hdu.edu.cn/showproblem.php?pid=6059
题意
Give you an array A[1..n],you need to calculate how many tuples (i,j,k) satisfy that (i< j< k) and ((A[i] xor A[j])<(A[j] xor A[k]))
题解
看了别人题解大半天,才终于明白,随便记下自己的理解
对于所有的 ((A[i] xor A[j])<(A[j] xor A[k]))
假设我们用字典树记录了A[1 ~ k-1],当前加入
字典树中以第30位为根,假设当前处理到了第 p 位
若
当
必然
1.
2.
当
注: 减去 dat[Fson].exn,dat[Fson].exn是 i > j 时 满足条件2 的情况
#include<stdio.h>#include<string.h>typedef long long LL;const int MAXN = 2e5 + 5;struct node {int num, exn, son[2]; } dat[31 * MAXN];LL ans = 0;int sz, cnt[31][2];inline void cle(int x) { dat[x].son[0] = dat[x].son[1] = dat[x].num = dat[x].exn = 0;}inline void add(int n, int o) { int z = 0; while(o >= 0) { int t = n>>o&1; int &Fson = dat[z].son[1-t]; int &Tson = dat[z].son[ t]; if(Fson) { ans += 1LL * dat[Fson].num * (dat[Fson].num - 1) / 2; ans += 1LL * dat[Fson].num * (cnt[o][1-t] - dat[Fson].num) - dat[Fson].exn; } if(Tson) { z = Tson; } else { z = Tson = ++sz; cle(Tson); } ++dat[z].num; ++cnt[o][t]; dat[z].exn += cnt[o][t] - dat[z].num; // all of j < i in this node --o; }}int main(){ int T, n, x; scanf("%d", &T); while(T--) { memset(cnt, 0, sizeof(cnt)); scanf("%d", &n); ans = sz = 0; cle(0); while(n--) { scanf("%d", &x); add(x, 30); } printf("%lld\n", ans); } return 0;}
阅读全文
0 0
- HDU 6059 Kanade's trio
- [HDU]6059 Kanade's trio
- HDU 6059 Kanade's trio
- hdu 6059 Kanade's trio
- HDU 6059 Kanade's trio 字典树
- Kanade's trio hdu 6059 字典树
- HDU 6059 Kanade's trio Trie + 计数
- hdu 6059 Kanade's trio(字典树)
- HDU 6059 Kanade's trio【字典树】
- HDU 6059 Kanade's trio 字典树 统计 容斥
- HDU-6059 Kanade's trio(字典树)
- HDU 6059 Kanade's trio(字典树)
- hdu 6059 Kanade's trio(字典树+位压缩)
- HDU 6059 Kanade's trio (字典树)
- HDU6059-Kanade's trio
- Kanade's trio
- Kanade's trio
- HDU 6059 Kanade's trio (字典树, 2017 Multi-Univ Training Contest 3)
- 深度学习遥感影像分类之数据集批量准备
- Angular八大核心之组件与组件树
- 安卓工作室 显示中文 android studio display Chinese
- JavaEE大型分布式电商项目 上海淘淘商城 29期
- java在后台输出js弹出对话框
- [HDU]6059 Kanade's trio
- 如何快速全面建立自己的大数据知识体系?
- 工作6年来的技术总结
- js高级教程 第五章-引用类型(中)
- 在tomcat中设置网络访问的虚拟路径和使用JDNI设置文件路径常量
- ios获取图片exif信息
- 一些js简单语法
- 图片拖拽
- PHP中的unset方法究竟能否释放内存