Kanade's trio

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 960    Accepted Submission(s): 361

Problem Description
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]))

There are T test cases.

1≤T≤20

1≤∑n≤5∗105

0≤A[i]<230

 
Input
There is only one integer T on first line.

For each test case , the first line consists of one integer n ,and the second line consists of n integers which means the array A[1..n]

 
Output
For each test case , output an integer , which means the answer.
 
Sample Input
1
5
1 2 3 4 5
 
Sample Output
6
Source
Recommend
liuyiding   |   We have carefully selected several similar problems for you:  6119 6118 6117 6116 6115 
 

题解:http://blog.csdn.net/dormousenone/article/details/76570172

这题:一直wa,把 tree[] 数组中的int改 long long 就错了,诶找了半天错误

#include <iostream>
#include<cstring>
#include<cstdio>
using namespace std; struct node
{
int cnt,ext;
int nxt[];
}tree[*];
int a[+],num[],cnt[][];
long long ans,ext;
int T,n,tsize; void cal(int k,long long c)
{
ans+=(tree[k].cnt-)*tree[k].cnt/;
ext+=tree[k].cnt*(c-tree[k].cnt)-tree[k].ext;
} void solve()
{
int tmp=;
for(int i=;i<=;i++)
{
if (!tree[tmp].nxt[num[i]])
tree[tmp].nxt[num[i]]=++tsize;
if (tree[tmp].nxt[-num[i]])
cal(tree[tmp].nxt[-num[i]],cnt[i][-num[i]]);
tmp=tree[tmp].nxt[num[i]];
tree[tmp].cnt++;
tree[tmp].ext+=cnt[i][num[i]]-tree[tmp].cnt;
}
return;
} int main()
{
scanf("%d",&T);
for(;T>;T--)
{
scanf("%d",&n);
memset(cnt,,sizeof(cnt));
memset(tree,,tsize*+);
tsize=;
ans=ext=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
int tmp=a[i];
for(int j=;j>=;j--)
{
cnt[j][tmp%]++;
num[j]=tmp%;
tmp/=;
}
solve();
}
printf("%lld\n",ans+ext);
}
return ;
}

hdu 6059 Kanade's trio(字典树)的更多相关文章

  1. HDU 6059 - Kanade's trio | 2017 Multi-University Training Contest 3

    思路来自题解(看着题解和标程瞎吉尔比划了半天) /* HDU 6059 - Kanade's trio [ 字典树 ]  |  2017 Multi-University Training Conte ...

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

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

  3. hdu 6059 Kanade's trio

    题 OwO http://acm.hdu.edu.cn/showproblem.php?pid=6059 解 由于每个数字最多是30位,枚举数字每一位考虑, 建一棵记录前缀(位的前缀,比如10拆成10 ...

  4. hdu 6059---Kanade's trio(字典树)

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

  5. HDU 4287 Intelligent IME(字典树数组版)

    Intelligent IME Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  6. HDU 4757 Tree 可持久化字典树

    Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4757 Des ...

  7. hdu 4099 Revenge of Fibonacci 字典树+大数

    将斐波那契的前100000个,每个的前40位都插入到字典树里(其他位数删掉),然后直接查询字典树就行. 此题坑点在于 1.字典树的深度不能太大,事实上,超过40在hdu就会MLE…… 2.若大数加法时 ...

  8. HDU 1247 - Hat’s Words - [字典树水题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1247 Problem DescriptionA hat’s word is a word in the ...

  9. HDU 1251 统计难题(字典树模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意:给出一些单词,然后有多次询问,每次输出以该单词为前缀的单词的数量. 思路: 字典树入门题. #inc ...

随机推荐

  1. Linux下编程学习一

    本篇主要记录一些在学习LINUX下编程时,, C和C++语言的一些基础的常识, 一. 函数指针 void MyFun(int x); 函数声明 void (*FunP)(int ); 函数指针声明 下 ...

  2. JVM(3) 垃圾回收器与内存分配策略

    文章内容摘自:深入理解java虚拟机 第三章   对象已死? 1. 引用计数算法: 给对象中添加一个引用计数器,每当有一个地方引用它时,计数器值就加1:当引用失效时,计数器值就减1:任何时刻计数器为0 ...

  3. laravel 环境配置

    一.composer 安装 1.确定为最新版本的PHP 2.进入Composer官网下载页面,在页面最下方Manual Download区域选择需要的版本下载. 3.将下载的composer.phar ...

  4. ElasticSearch(一)ElasticSearch的应用场景及为什么要选择ElasticSearch?

    先了解一下数据的分类 结构化数据又可以称之为行数据,存储在数据库里,可以用二维表结构来逻辑表达实现的数据.其实就是可以能够用数据或者统一的结构加以表示的数据.比如在数据表存储商品的库存,可以用整型表示 ...

  5. Windows下Yii2框架的两种安装方式及升级最新版

    第一种:归档文件形式安装(适合于没有安装composer的机器) 进入下载页https://www.yiiframework.com/download,选择下载第一个 下载完成之后是一个压缩包,解压文 ...

  6. cordova 插件

    1.移动端WebApp开发,如何实现状态栏沉浸式效果? cordova-plugin-fullscreen 2. cordova热更新插件-不发布应用市场动态更新APP源码 https://githu ...

  7. centos下利用mail命令进行邮件发送

    centos下默认自带mail命令: 可以用如下命令查看存放位置: which mail 结果如下: 如果没有安装可以使用 如下命令安装 yum -y install mailx 利用mail命令进行 ...

  8. scrapy之手机app抓包爬虫

    手机App抓包爬虫 1. items.py class DouyuspiderItem(scrapy.Item): name = scrapy.Field()# 存储照片的名字 imagesUrls ...

  9. Lucene 的 Scoring 评分机制

    转自: http://www.oschina.net/question/5189_7707  Lucene 评分体系/机制(lucene scoring)是 Lucene 出名的一核心部分.它对用户来 ...

  10. codeforces 578c - weekness and poorness - 三分

    2017-08-27 17:24:07 writer:pprp 题意简述: • Codeforces 578C Weakness and poorness• 给定一个序列A• 一个区间的poornes ...