#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);
}
}

hdu6059[字典树+思维] 2017多校3的更多相关文章

  1. hdu6035[dfs+思维] 2017多校1

    /*hdu6035[dfs+思维] 2017多校1*/ //合并色块, 妙啊妙啊 #include<bits/stdc++.h> using namespace std; ; const ...

  2. hdu6074[并查集+LCA+思维] 2017多校4

    看了标答感觉思路清晰了许多,用并查集来维护全联通块的点数和边权和. 用另一个up[]数组(也是并查集)来保证每条边不会被重复附权值,这样我们只要将询问按权值从小到大排序,一定能的到最小的边权和与联通块 ...

  3. Choosing The Commander CodeForces - 817E (01字典树+思维)

    As you might remember from the previous round, Vova is currently playing a strategic game known as R ...

  4. codeforces 842 D. Vitya and Strange Lesson(01字典树+思维+贪心)

    题目链接:http://codeforces.com/contest/842/problem/D 题解:像这种求一段异或什么的都可以考虑用字典树而且mex显然可以利用贪心+01字典树,和线段树差不多就 ...

  5. HDU6038-Function-数学+思维-2017多校Team01

    学长讲座讲过的,代码也讲过了,然而,当时上课没来听,听代码的时候也一脸o((⊙﹏⊙))o 我的妈呀,语文不好是硬伤,看题意看了好久好久好久(死一死)... 数学+思维题,代码懂了,也能写出来,但是还是 ...

  6. hdu6059 Kanade's trio 字典树+容斥

    转自:http://blog.csdn.net/dormousenone/article/details/76570172 /** 题目:hdu6059 Kanade's trio 链接:http:/ ...

  7. Trie树/字典树题目(2017今日头条笔试题:异或)

    /* 本程序说明: [编程题] 异或 时间限制:1秒 空间限制:32768K 给定整数m以及n个数字A1,A2,..An,将数列A中所有元素两两异或,共能得到n(n-1)/2个结果,请求出这些结果中大 ...

  8. HDU 6059 17多校3 Kanade's trio(字典树)

    Problem Description Give you an array A[1..n],you need to calculate how many tuples (i,j,k) satisfy ...

  9. 2017ACM暑期多校联合训练 - Team 6 1001 HDU 6096 String (字符串处理 字典树)

    题目链接 Problem Description Bob has a dictionary with N words in it. Now there is a list of words in wh ...

随机推荐

  1. AndroidStudio第一次提交项目代码到git服务器/github

    虽然使用AndroidStudio(以下简称as)开发并使用git管理代码已经有很长时间,但是第一次提交项目到git依然会很不顺利,网上的文章或许因为所使用版本比较老,并不一定完全凑效,因此写此笔记做 ...

  2. 继承UIView的初始化 、重绘、以及绘制图片

    大家对于UIViewController的生命周期都相当了解了.但是对于继承UIView的子类能做什么,却很少有文章介绍的. 1.  -initWithFrame:(CGRect)rect是view指 ...

  3. 补充---spring多线程任务调度

    在spring任务调度的基础上增加多线程 三种方式: (1)使用OpenSymphony Quartz 调度器 (2)使用JDK Timer支持类 (3)SpringTaskExecutor抽象 sp ...

  4. 验证 .NET 4.6 的 SIMD 硬件加速支持的重要性

    SIMD 的意思是 Single Instruction Multiple Data.顾名思义,一个指令可以处理多个数据. .NET Framework 4.6 推出的 Nuget 程序包 Syste ...

  5. (三)maven之一个基本的pom.xml

    一个基本项目的pom.xml文件,通常会有以下三部分: 一.项目坐标,信息描述等. <modelVersion>4.0.0</modelVersion> <groupId ...

  6. ActiveMQ消息丢失怎么解决?

    在消息发送过程中消息丢失的话该怎么解决(包括网络原因): 解决思路: 可以把消息唯一ID,存到表里面,当消息接受端可以获取到这个ID,就给服务端一个回复IF,消息发送出去,没有回复,THEN一直循环发 ...

  7. 关于HTML5中Video标签无法播放mp4的解决办法

    1.首先先排除掉代码问题.路径问题.浏览器不支持问题等常规问题,这些问题另行百度. <video width="500px" height="300px" ...

  8. Core Foundation 框架

    Core Foundation框架 (CoreFoundation.framework) 是一组C语言接口,它们为iOS应用程序提供基本数据管理和服务功能.下面列举该框架支持进行管理的数据以及可提供的 ...

  9. js 前端不调接口直接下载图片

    // 下载图片 downPhoto (path) { this.downloadFiles(path) }, // 下载 downloadFiles (content) { console.log(c ...

  10. (2)JSTL的fmt国际化标签库

    format标签库:做国际化格式化,分两类 : 国际化核心标签:<fmt:setLocale>.<fmt:bundle>.<fmt:setBundle>.<f ...