#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int trie[ * ][];
int no[ * ];
int sz[ * ];
int sum[][];
int T, n, temp, tot = ;
LL ans = ;
void solve(int x) {
int now = ;
for (int i = ; ~i; i--) {
int bit = (x & ( << i)) ? : ;
sum[i][bit]++;
if (!trie[now][bit]) {
trie[now][bit] = ++tot;
}
if (trie[now][ ^ bit]) { //存在兄弟节点,即有符合的(Ai,Aj)
int bro = trie[now][ ^ bit];
ans += 1LL * sz[bro] * (sz[bro] - ) / ;
ans += 1LL * (sum[i][ ^ bit] - sz[bro]) * sz[bro] - no[bro];
}
now = trie[now][bit];
sz[now]++;
no[now] += sum[i][bit] - sz[now];//除去不符合j>i的(Ai,Aj),要累加
//cout << now << ' ' << no[now] << endl;
}
}
void init() {
memset(trie, , sizeof(trie));
memset(no, , sizeof(no));
memset(sum, , sizeof(sum));
memset(sz, , sizeof(sz));
ans = , tot = ;
}
int main() {
scanf("%d", &T);
while (T--) {
init();
scanf("%d", &n);
for (int i = ; i < n; i++) {
scanf("%d", &temp);
solve(temp);
}
printf("%lld\n", ans);
}
}

最新文章

  1. w3svc服务启动 不了,错误 1068:依赖服务或组件无法启动
  2. poj1417 带权并查集 + 背包 + 记录路径
  3. winform(容器、打印、对话框)
  4. mysql完整备份时过滤掉某些库
  5. ES6-函数扩展
  6. hadoop作业调优参数整理及原理(转)
  7. Eclipse Gtk+
  8. java如何追加写入txt文件
  9. 【Android】跟着教程做の学习笔记
  10. Android多媒体数据库之MediaStore研究
  11. 结构体buf_block_t
  12. C# and JSON
  13. vcastr2.0插件超级简单使用
  14. MFC获取当前时间
  15. ASP.NET导入Excel到SQL数据库
  16. Ffmpeg和SDL如何同步视频(转)
  17. hadoop 学习
  18. asp.net中实现MD5加密、解密的方法
  19. String详解说明
  20. [2]十道算法题【Java实现】

热门文章

  1. win10 64位 mysql安装过程出现status显示failed
  2. 屏幕旋转时 Activity 的生命周期 —— 测试与结论
  3. linux各文件夹的作用(转)
  4. iis的网站发布
  5. ubuntu 14.04 安装npm
  6. 提取循环中包含continue的语句封装成方法
  7. 用”人话”解释CNN —— 对单个特征图进行视觉化
  8. CPP-基础:windows api 多线程---互斥量、信号量、临界值、事件区别
  9. java运行环境jdk的安装和环境变量的配置教程
  10. javaEE(14)_文件上传下载