求数组中i<j<k 并且ai^aj<aj^ak的三元组组数

枚举插入ak,让ak中每一位作为最高位,查找字典树内最高位不同的数字数量

注意把ak的每个前缀做一个bad标记

存储让这个前缀作为i可以与字典树内形成i,j对的个数,这些不满足i<j

ai  : 1 1 0 1

aj  : ? 0 0 0

ak : 1 0 0 1

结合这个图会直观点。。

#include<bits/stdc++.h>
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string.h>
#include<iostream>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<iomanip>
using namespace std;
#define ll long long
#define pb push_back
#define FOR(a) for(int i=1;i<=a;i++)
const int inf=0x3f3f3f3f;
const int maxn=5e5+9;  struct NODE{int cnt;int nxt[2];int bad;
}trie[maxn*30];int sz;
int dig[30];
int cnt[30][2];
ll ans;
int arr[maxn];void cal(int p,int cnt){ans+=1ll*trie[p].cnt*(trie[p].cnt-1)>>1;             //ai,aj都在前缀内选ans+=1ll*trie[p].cnt*(cnt-trie[p].cnt)-trie[p].bad;  //ai在前缀,aj不在
}void insert(){int now=0;for(int i=0;i<30;i++){if(!trie[now].nxt[dig[i]]){trie[now].nxt[dig[i]]=++sz;}if(trie[now].nxt[1-dig[i]]){cal(trie[now].nxt[1-dig[i]],cnt[i][1-dig[i]]);}now=trie[now].nxt[dig[i]];trie[now].cnt++;trie[now].bad+=cnt[i][dig[i]]-trie[now].cnt;}
}int main(){int T;scanf("%d",&T);while(T--){memset(trie,0,sizeof trie);memset(cnt,0,sizeof cnt);int n;scanf("%d",&n);sz=0,ans=0;FOR(n){scanf("%d",&arr[i]);for(int j=29;j>=0;j--){dig[j]=arr[i]%2;cnt[j][arr[i]%2]++;arr[i]/=2;}insert();}printf("%lld\n",ans);}
}

学了字典树基本没用过。。

接着补题之前做做异或题吧。。

转载于:https://www.cnblogs.com/Drenight/p/8611291.html

Kanade's trio 2017多校#3 trie相关推荐

  1. hdu 6059 Kanade's trio

    Problem acm.hdu.edu.cn/showproblem.php?pid=6059 Reference HDU 6059 Kanade's trio (字典树, 2017 Multi-Un ...

  2. 2017 多校3 hdu 6061 RXD and functions

    2017 多校3 hdu 6061 RXD and functions(FFT) 题意: 给一个函数\(f(x)=\sum_{i=0}^{n}c_i \cdot x^{i}\) 求\(g(x) = f ...

  3. 2017 多校2 hdu 6053 TrickGCD

    2017 多校2 hdu 6053 TrickGCD 题目: You are given an array \(A\) , and Zhu wants to know there are how ma ...

  4. hdu6103[尺取法] 2017多校6

    /*hdu6103[尺取法] 2017多校6*/ #include <bits/stdc++.h> using namespace std; int T, m; char str[2000 ...

  5. 2017 多校4 Wavel Sequence

    2017 多校4 Wavel Sequence 题意: Formally, he defines a sequence \(a_1,a_2,...,a_n\) as ''wavel'' if and ...

  6. 2017多校第3场 HDU 6058 Kanade's sum 双链表,思维

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6058 题外话:这场多校,真心感觉自己的无力,全队都发挥的很差,结束的时候排名掉到了90多,后期没做出字 ...

  7. 2017 Multi-University Training Contest - Team 3:1004. Kanade's trio(01字典树)

    感觉很多时候字典树都是这种题的万能解 (具体规则or什么是字典树:http://blog.csdn.net/jaihk662/article/details/53930927) 建立两棵01字典树,对 ...

  8. HDU 6058 - Kanade's sum | 2017 Multi-University Training Contest 3

    /* HDU 6058 - Kanade's sum [ 思维,链表 ] | 2017 Multi-University Training Contest 3 题意:给出排列 a[N],求所有区间的第 ...

  9. 2017 多校训练第二场 HDU 6047 Maximum Sequence(贪心+优先队列)

    Maximum Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

最新文章

  1. RateLimiter 源码分析(Guava 和 Sentinel 实现)
  2. 机器学习笔记(五)神经网络
  3. Python进阶_wxpy学习:异常chu'li
  4. 修改intellij(idea)中mybatis对应的xml背景颜色
  5. 教你如何申请CCNP的电子证书
  6. MATLAB中三维曲面命令
  7. Elasticsearch(待学习)
  8. python写彩票预测软件_python写彩票预测软件
  9. android开源系统brvah,Brvah——一个强大的Adapter框架
  10. 8根网线的排序和作用
  11. Git LFS报错“Git LFS is not installed”
  12. c语言编写生日祝福语大全,生日祝福语(精选50句)
  13. RandomAccessFile 随机读写文件
  14. 研发管理学习笔记1-研发管理的目标是什么
  15. C语言编程>第二十周 ② 下列给定程序中,函数fun的功能是:求出数组中最大数和次最大数,并把最大数和b[0]中的数对调、次最大数和b[1]中的数对调。
  16. 最大质因子递归解法python
  17. 你需要立即停止的9个习惯! 2012-03-11 10:01:41
  18. 《Java I/O》Chapter 1
  19. H.264区分NALU startCode和NALU 内部和startCode相同的内容
  20. table数据刷新;v-if刷新el-table表格

热门文章

  1. Pascal's Triangle
  2. 手动新增swap分区
  3. NeHe OpenGL第三十九课:物理模拟
  4. windows 2008 (非R2)使用批处理文件调整组策略过程记录
  5. 在Unity中创建3D直升机游戏
  6. Java怎么定义图片公共路径_【Java】springboot配置图片访问路径
  7. with as python_python - with as的用法
  8. AS更改初始布局遇到的问题
  9. (C++) A+B 输入输出练习IV 每行的第一个数N,表示本行后面有N个数。 如果N=0时,表示输入结束,且这一行不要计算。
  10. javascript的垃圾回收机制指的是什么